如何用shell编写一个简单的计算器
1个回答
展开全部
如果只做四个简单的运算这应应该可以
shell脚本代码如下:
#!/bin/bash
read -p "input num1:" a
read -p "input num2:" b
read -p "input operator:" o
case $o in
+) let "res=a + b"
echo $res;;
-) let "res=a - b"
echo $res;;
/) awk 'BEGIN{printf "%.2f\n",'$a'/'$b'}';;
*) let "res=a * b"
echo $res;;
esac
shell脚本代码如下:
#!/bin/bash
read -p "input num1:" a
read -p "input num2:" b
read -p "input operator:" o
case $o in
+) let "res=a + b"
echo $res;;
-) let "res=a - b"
echo $res;;
/) awk 'BEGIN{printf "%.2f\n",'$a'/'$b'}';;
*) let "res=a * b"
echo $res;;
esac
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询