美文网首页
Shell script: 循环

Shell script: 循环

作者: louyang | 来源:发表于2017-12-28 09:13 被阅读5次

语法:

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: 循环

      本文链接:https://www.haomeiwen.com/subject/ngpxixtx.html