通过参数传递N个正整数给脚本,求其和 #!/bin/bash Sum=0 for I in [email protected] do Sum=$[$I+$Sum] done echo "$Sum"
使用shift
#!/bin/bash Sum=0 for I in `seq 1 $#` do Sum=$[$Sum+$1] shift done echo "$Sum"
时间: 2024-10-26 09:32:00
通过参数传递N个正整数给脚本,求其和 #!/bin/bash Sum=0 for I in [email protected] do Sum=$[$I+$Sum] done echo "$Sum"
使用shift
#!/bin/bash Sum=0 for I in `seq 1 $#` do Sum=$[$Sum+$1] shift done echo "$Sum"