练习脚本:一个整数加法shell
时间:2006-07-24 来源:wind.zhu
bash-2.05$ more add.sh
#!/bin/sh
echo "请输入第一个整数:\c"
read count1
echo "请输入第二个整数:\c"
read count2
tmp=$count1
n1=$count1
if [ $count1 -ge $count2 ];then
echo "输入的第一整数应比二个整数小"
exit 1
else
echo "please waiting.\c"
while [ $tmp -lt $count2 ]
do
tmp=`expr $tmp + 1`
count1=`expr $count1 + $tmp`
echo ".\c"
done
echo " \n "
if [ `expr $n1 + 1` -eq $count2 ];then
echo "$n1 "+" $count2 "=" $count1 "
else
echo "$n1 "+" "`expr $n1 + 1`" "+" "..." "+" $count2 "=" $count1 "
fi
fi
#!/bin/sh
echo "请输入第一个整数:\c"
read count1
echo "请输入第二个整数:\c"
read count2
tmp=$count1
n1=$count1
if [ $count1 -ge $count2 ];then
echo "输入的第一整数应比二个整数小"
exit 1
else
echo "please waiting.\c"
while [ $tmp -lt $count2 ]
do
tmp=`expr $tmp + 1`
count1=`expr $count1 + $tmp`
echo ".\c"
done
echo " \n "
if [ `expr $n1 + 1` -eq $count2 ];then
echo "$n1 "+" $count2 "=" $count1 "
else
echo "$n1 "+" "`expr $n1 + 1`" "+" "..." "+" $count2 "=" $count1 "
fi
fi
相关阅读 更多 +