##### 循环 #####
有四种方式:while ... do ... done,until ... do ... done,for ... do ... done,for ... in ... do ... done
## while ... do ... done
while condition
do
//do what you want
done
解释:当condition不成立时终止循环
## until ... do ... done
until condition
do
//do what you want
done
解释:刚好和while 相反,当condition成立时终止循环
## for ... do ... done
for ((初始值; 条件; 执行步骤))
do
//do what you want
done
解释:例子说明问题,1到100的和 ~~
sum=0
for (( i=1; i<=100; i++ )
do
sum=$(($sum+$i))
done
## for ... in ... do ... done
这个比较特别,第一次见到,哈
for var in con1 con2 con3 ...
do
//do what you wan
done
解释:执行第一次循环时,变量var的值是con1; 第二次时是con2,第三次是con3;...依此类推
for color in red yellow white
do
echo "The color is $color"
done