until循环语法格式:
until CONDITION do statement done 说明: until进入循环的条件是:condition不成立时,就执行循环。 until进入循环的条件正好和while相反,while进入循环的条件是:condition成立时,就进入循环。
示例1:while循环
[[email protected] Learn]# cat while.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]# ./while.sh 5050 [[email protected] Learn]#
示例2:until循环
[[email protected] Learn]# cat until.sh #!/bin/bash declare -i sum=0 declare -i i=100 until [ $i -eq 0 ] do let sum+=$i let i-=1 done echo $sum [[email protected] Learn]# ./until.sh 5050 [[email protected] Learn]#
shell编程(十四)--- until循环
时间: 2024-11-23 02:47:46