while循环用于不断执行一系列命令,也用于从输入文件中读取数据;命令通常为测试条件。其格式为:
while command do Statement(s) to be executed if command is true done
下面是一个基本的while循环的例子
#!/bin/bash COUNTER=0 while [ $COUNTER -lt 5 ] do COUNTER=`expr $COUNTER + 1` echo $COUNTER done
while循环也可用于读取键盘信息
#!/bin/bash echo ‘type <CTRL-D> to terminate‘ echo -n ‘enter something: ‘ while read FILM do echo "you enter $FILM" echo -n ‘enter something: ‘ done
时间: 2024-10-19 12:17:34