1、罗列式
for VARIABLE in 1 2 3 4 5 .. N
do
command1
command2
commandN
done
#!/bin/bash
for i in 1 2 3 4 5
do
echo "Welcome $i times"
done
2、使用rang
#!/bin/bash
for i in {1..5}
do
echo "Welcome $i times"
done
3、使用rang and step
echo "Bash version ${BASH_VERSION}..."
for i in {0..10..2}
do
echo "Welcome $i times"
done
4、使用seq
for i in `seq 1 5`
do
echo "Welcome $i times"
done
5、和高级语言一样的for
for (( EXP1; EXP2; EXP3 ))
do
command1
command2
command3
done
#!/bin/bash
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times..."
done
#!/bin/bash
for (( ; ; ))
do
echo "infinite loops [ hit CTRL+C to stop]"
done