欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

shell中while循环的常用写法

程序员文章站 2024-03-23 21:44:22
...

写法一:

#!/bin/sh
int=1
while (( "$int < 10" ))
do
    echo "$int"
    let "int++"
done

写法二:

#!/bin/sh
echo "please input the num"
read num
sum=1
while [ "$num" -gt 0 ]
do
    let "sum=sum*num"
    let "num--"
done
echo "the sum is $sum"