#!/bin/bash
# sum.sh
# 获取随机数量的参数,相加并打印结果
#
total=0
#
# $# 表示参数的数量
# for 循环获取每个参数
# ${!i} 表示返回第i个参数
#
for (( i = 1; i <= $#; i++ ))
do
    total=$[ $total + ${!i} ]
done
#
echo Total = $total
#

 

#!/bin/bash
# 使用$@相加所有参数
# sum1.sh
#
total=0
#
for param in $@
do
    total=$[ $param + $total ]
done
echo
echo Total = $total
echo

 

bash shell——sum

相关文章:

  • 2021-08-04
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2022-01-05
  • 2021-08-09
  • 2021-08-20
  • 2022-01-08
  • 2021-06-15
相关资源
相似解决方案