#! /bin/bash # return sum of arguments let sum=0 for f in $* do sum=$(($sum+$f)) done printf "sum is %d \n" $sum
其中的for循环可以用while替换
while [ $# -ne 0 ] do sum=$(($sum+$1)) shift done
时间: 2024-10-09 23:57:43
#! /bin/bash # return sum of arguments let sum=0 for f in $* do sum=$(($sum+$f)) done printf "sum is %d \n" $sum
其中的for循环可以用while替换
while [ $# -ne 0 ] do sum=$(($sum+$1)) shift done