while,until

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

 

posted @ 2017-08-20 11:06  xiongjiawei  阅读(160)  评论(0编辑  收藏  举报