for语句–shell

来源:互联网 发布:js div滑动效果 编辑:程序博客网 时间:2024/06/05 19:05
for 变量名 in 列表do    命令1    命令2…done

打印字符串列表

#!/bin/bash#打印字符串到结束,包括空格for loop in "orange red blue grey "doecho "this is fruit $loop"done

for循环使用ls命令

#!/bin/bashfor loop in 'ls 'do$loopdone

对for循环使用参数

#!/bin/bash#在for循环中省去 in列表选项时,它将接受命令行位置参数作为参数for paramsdoecho "you supplied $params as a cmd line"done

for循环统计文件数目

#!/bin/bash#统计当前目录下文件书目iCounter=0for files in *doiCounter=`expr $iCounter + 1`doneecho "There are $iCounter files in the `pwd` "

for循环嵌入

for 变量名1 in 列表1do    for 变量名2 in 列表2    do          命令1    donedone


原创粉丝点击