首页 > 其他 > 详细

while,until

时间:2017-08-20 12:05:59      阅读:251      评论:0      收藏:0      [点我收藏+]

while

sum=0
while [ $i -le 100 ]  注释:中括号写的条件判断式中不能用<、=、>这类符号,要用-lt、-eq、-gt这类符号,且变量前要用$来取值
        do
                sum=$(($sum+$i))
                i=$(($i+1))
        done
echo "sum=$sum"

运行结果:

[root@localhost ~]# ./myShell.sh 
sum=5050

 


until

#!/bin/bash

i=1
sum=0
until test $i -gt 100  注释:比较符都是双字母,没有g、l、e,要用gt、lt、eq
        do
                sum=$[$sum+$i]
                i=$(($i+1))
        done
echo "sum=$sum"

运行结果:

[root@localhost ~]# ./myShell.sh 
sum=5050

 

while,until

原文:http://www.cnblogs.com/xiongjiawei/p/7399269.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!