shellで1~100までの偶数データの合計する

shellコード下記:
#!/bin/bash
# description: the sum even of 1 to 100

#sum変数を定義

declare -i sum=0
let count=0
while [ $count -le 100 ];do
let rst=$count%2
# if [ $rst -eq 0 ];then
# let sum+=$count
#fi
[ $rst -eq 0 ] && let sum+=$count
let count++
done
echo “合計$sum."

shellscript

Posted by arkgame