脚本1:


#!/bin/bash
let EVENNUM=0
let ODDNUM=0
for I in {1..100};do
 if [ $(($I%2)) -eq 0 ];then
    let EVENNUM=$EVENNUM+$I
 elif [ $(($I%2)) -eq 1 ] ;then
    let  ODDNUM=$ODDNUM+$I
 fi
done
    echo "\$EVENNUM= $EVENNUM" 
    echo "\$ODDNUM= $ODDNUM"

 


脚本2:


#!/bin/bash
let EVENNUM=0
let ODDNUM=0
read -p "NUM1:"  NUM1
read -p "NUM2:"  NUM2
for I in $(seq $NUM1 $NUM2);do
 if [ $(($I%2)) -eq 0 ];then
    let EVENNUM=$EVENNUM+$I
 elif [ $(($I%2)) -eq 1 ] ;then
    let  ODDNUM=$ODDNUM+$I
 fi
done
    echo "\$EVENNUM= $EVENNUM" 
    echo "\$ODDNUM= $ODDNUM"