while command do Statement(s) to be executed if command is true done命令执行完毕,控制返回循环顶部,从头开始直至测试条件为假。
COUNTER=0 while [ $COUNTER -lt 5 ] do COUNTER='expr $COUNTER+1' echo $COUNTER done运行脚本,输出:
1 2 3 4 5while循环可用于读取键盘信息。下面的例子中,输入信息被设置为变量FILM,按<Ctrl-D>结束循环。
echo 'type <CTRL-D> to terminate' echo -n 'enter your most liked film: ' while read FILM do echo "Yeah! great film the $FILM" done运行脚本,输出类似下面:
type <CTRL-D> to terminate enter your most liked film: Sound of Music Yeah! great film the Sound of Music
原文地址:http://blog.csdn.net/wu20093346/article/details/47253365