while循环适用于循环次数未知的场景。
语法格式: while CONDITION do statement …… done 说明:while是当CONDITION成立的时候就执行循环,当条件不成立时,退出循环。
示例1:计算从1加到100.
[[email protected] Learn]# cat while1.sh #!/bin/bash declare -i sum=0 declare -i i=0 while [ $i -le 100 ] do let sum+=$i let i+=1 done echo $sum [[email protected] Learn]# chmod +x while1.sh [[email protected] Learn]# ./while1.sh 5050 [[email protected] Learn]#
shell编程(十三) --- while循环,布布扣,bubuko.com
时间: 2024-10-29 04:48:39