#!/bin/bash
sum=1
for i in `seq 1 100`;do
sum=`expr $i \* $i + $sum`
done
echo "From 1 to 100: $sum"
#!/bin/bash
for i in {1..4}
do
let SUM=$SUM+$i*$i
done
echo $SUM
#!/bin/bash
declare -i sum
declare -i i
i=1
while [ $i -le 100 ];
do
sum=$sum+$i*$i
i=$i+1
done
echo $sum
注意里面得空格,不能随意删减。