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

 

相关文章:

  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-11-03
  • 2021-12-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-10-26
  • 2022-12-23
相关资源
相似解决方案