还加了一点自己的修改,荡来的那个有些问题。
道客巴巴的文件链接
题目
这个为shell脚本——exe4.sh中的内容
#! /bin/bash
while :
do
read -p "Please Input the first number: " n1
expr $n1 + 0 &> /dev/null
if [ $n1 -gt 0 -a $n1 -lt 100 ]
then
echo "Your First Number is $n1"
echo
break
else
echo "NumberRangeError,will be exit"
exit 1
fi
done
while :
do
read -p "Inpur the second number: " n2
expr $n2 + 0 &> /dev/null
if [ $n2 -gt 0 -a $n2 -lt 100 ]
then
echo "Second number is $n2 "
echo
break
else
echo "NumberRangeError, will be exit"
fi
done
echo "Pleast chooose the arithmetic type: "
echo "[a]Add"
echo "[s]Subtract"
echo "[m]Multiply"
echo "[d]Divide"
echo "[r]Remainder"
echo "[q]Quit"
while :
do
read -p "Your Input: " m
case $m in
"a")
re=`expr $n1 + $n2`
echo "$n1+$n2 = $re"
;;
"s")
re2=`expr $n1 - $n2`
echo "$n1 - $n2 = $re2"
;;
"m")
re3=`expr $n1 \* $n2`
echo "$n1 * $n2 = $re3"
;;
"d")
re4=`expr $n1 / $n2`
echo "$n1 / $n2 = $re4"
;;
"r")
re5=$(( $n1 % $n2 ))
echo "$n1 % $n2 = $re5"
;;
"q")
break;;
esac
done
执行命令
Virtual-Machine:~$ chmod +x exe4.sh
Virtual-Machine:~$ ./exe4.sh
Please Input the first number: