num=0 while ((num <= 100)); do total=`expr $total + $num` num="$num + 1" done echo "$total" ~ 或者 #!/bin/bash i=0 n=0 while [ $i -le 100 ] ;do let n=$n+$i let i=$i+1 done echo $n 利用for循环求和: #!/bin/bash total=0 for ((j=1;j<=100;j++)); do...
!/bin/bashsum=0for i in {1..100}do if [ $(( $i % 3 )) -eq 0 ] then echo $i sum=$(( $sum + $i )) fidoneecho "sum is: $sum"保存为sum.sh