Shell script: 循环

语法:

for name [ in [word ... ]]
do
    compound-list
done

例如:

#!/bin/bash
for i in {1..3}
do
   echo "Welcome $i times"
done

运行结果:

Welcome 1 times
Welcome 2 times
Welcome 3 times

另外一种写法,看上去与C类似:

#!/bin/bash
for ((i = 1; i <= 3; i++));
do
   echo "Welcome $i times"
done

运行结果和上面是一样的。

参考
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

你可能感兴趣的:(Shell script: 循环)