sum=0
if [ $# -ne 2 ]
then
echo "Please input two numbers!"
elif [ $1 -gt $2 ]
then
echo "The seconde number must be great the first number."
else
for i in $(seq $1 $2)
do
sum=`expr $sum + $i`
done
echo "\"$1~$2\" sum is $sum"
fi
#执行结果
#[root@localhost opt]# ./b.sh 3 6
#"3~6" sum is 18
#[root@localhost opt]# ./b.sh 3
#Please input two numbers!
#[root@localhost opt]# ./b.sh 3 5 6
#Please input two numbers!
#[root@localhost opt]# ./b.sh 3 2
#The seconde number must be great the first number.
#[root@localhost opt]# ./b.sh 3 25
#"3~25" sum is 322
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)