数字形式
for i in {1..100} do echo $i done
详细列出,适用于字符且项数不多的情况
for File in 1 2 3 4 5 do echo $File done
遍历文件
for shname in `ls *.sh` do name=`echo "$shname" | awk -F. '{print $1}'` echo $name done
循环语法,像C语言,但请记得双括号
for((i=1;i<100;i++)) do if((i%3==0)) then echo $i continue fi done
使用seq
for i in `seq 100` do if((i%3==0)) then echo $i continue fi done
while循环
min=1 max=100 while [ $min -le $max ] do echo $min min=`expr $min + 1` done
while双括号形式,但请注意赋值
i=1 while(($i<100)) do if(($i%4==0)) then echo $i fi i=$(($i+1)) done