荡来了一只sehll脚本:写一个脚本,它能够执行简单计算器的功能

还加了一点自己的修改,荡来的那个有些问题。
道客巴巴的文件链接

题目

这里写图片描述

这个为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: 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值