for循环练习一、分别计算100以内奇数和偶数的和
1 #showsum.sh
2 #!/bin/bash
3 #
4 declare -i EVENSUM=0
5 declare -i ODDSUM=0
6
7 for I in {1..100}; do
8 if [ $[$I%2] -eq 0 ]; then
9 let EVENSUM+=$I
10 else
11 let ODDSUM+=$I
12 fi
13 done
14 echo "Odd sum is: $ODDSUM."
15 echo "Even sum is: $EVENSUM."
[root@localhost ~]# ./showsum.sh
Odd sum is: 2500.
Even sum is: 2550.
for循环练习二、