十一、while语句

语法1:

while [ 条件判断式 ]    #注意while和[]之间有空格,条件判断式两侧是有空格的
do
程序语句
done

 如果条件判断式为真,就执行do程序,继续循环;为假,则跳出while循环

 

[root@localhost files]# vi 3.sh

#!/bin/bash
sum=0
i=5
while [ $sum -le $i ]
do
 sum=$[$sum+1]
 echo $sum
done
#结果
[root@localhost files]# chmod u+x 3.sh
[root@localhost files]# ./3.sh
1
2
3
4
5
6

 

posted @ 2025-11-18 08:55  chao_xiong  阅读(4)  评论(0)    收藏  举报