星空网 > 软件开发 > 操作系统

Linux Shell系列教程之(十)Shell for循环

本文是Linux Shell系列教程的第(十)篇,更多Linux Shell教程请看:Linux Shell系列教程

基本任何语言都有自己的循环语句,Shell当然也不例外,今天就为大家介绍下Shell for循环的用法。

Linux Shell系列教程之(十)Shell for循环images/loading.gif' data-original="http://cdn.linuxdaxue.com/wp-content/uploads/2016/05/Shell-for_thumb.jpg" width="504" height="304" border="0" />

Shell for循环语法

Shell for循环的语法如下所示

for 变量 in 列表do  command1  command2  ...  commandNdone

列表是一组值(数字、字符串等)组成的序列,每个值通过空格分隔。每循环一次,就将列表中的值依序放入指定的变量中,然后重复执行命令区域(在do和done 之间),直到所有元素取尽为止。

Shell for循环示例

接下来通过示例的方式给大家介绍下Shell for循环的用法。

for loop in one two tree fourdo  echo "I am : $loop"done

输出结果:

I am : oneI am : twoI am : treeI am : four

可以顺序输出字符串的单词,示例:

for str in I am linuxdaxuedo  echo $strdone

输出结果:

Iamlinuxdaxue

可以显示当前目录下的文件,示例:

for file in ./*do  echo $filedone

输出结果:

./a.sh./automake./automonitor./crzk./makedir./shell_start./sql./submit

Shell for循环命令是比较容易掌握的,今天就先给大家介绍到这里。更多Shell教程请看:Linux Shell系列教程


本文由Linux技术达人【daxue】发表在:Linux大学
本文固定链接:Linux Shell系列教程之(十)Shell for循环



原标题:Linux Shell系列教程之(十)Shell for循环

关键词:linux

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流