for 变量名 in 列表 do 命令1 命令2… done 打印字符串列表 #!/bin/bash #打印字符串到结束,包括空格 for loop in "orange red blue grey " do echo "this is fruit $loop" done for循环使用ls命令 #!/bin/bash for loop in 'ls ' do $loop done 对for循环使用参数 #!/bin/bash #在for循环中省去 in列表选项时,它将接受命令行位置参数作为参数 for params do echo "you supplied $params as a cmd line" done for循环统计文件数目 #!/bin/bash #统计当前目录下文件书目 iCounter=0 for files in * do iCounter=`expr $iCounter + 1` done echo "There are $iCounter files in the `pwd` " for循环嵌入 for 变量名1 in 列表1 do for 变量名2 in 列表2 do 命令1 done done