使用shell脚本,编写一个计算器

echo "============================="
echo "        Shell 计算器          "
echo "============================="
read -p "请输入第一个整数:" num1
read -p "请选择你的运算符号
加法(+),减法(-),乘法(x),除法(/),取余(%)" fh
read -p "请输入第二个整数:" num2

if [ $fh = + ]
   then
      echo "结果为:$(expr $num1 + $num2)"
elif [ $fh = - ]
   then
      echo "结果为:$(expr $num1 - $num2)"
elif [ $fh = x ]
   then
	  echo "结果为:$(expr $num1 \* $num2)"
elif [ $fh = '/' ]
   then
      echo "结果为:$(expr $num1 / $num2)"
elif [ $fh = % ]
   then
      echo "结果为:$(expr $num1 % $num2)"
else
      echo "输入错误"
fi
发布了74 篇原创文章 · 获赞 150 · 访问量 6539

猜你喜欢

转载自blog.csdn.net/weixin_45682995/article/details/103259336