Linux, a small shell script simple calculator

Up on yesterday's simple calculator

#!/bin/bash

for i in `seq 1000`
do
echo "此计算器中乘法用x表示  除法用/表示!"
echo "请输入第一个整数"
read num1
expr $num1 + 1 >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "输出的$num1不是整数请重新输入"
exit
fi
echo "请输入第二个整数:"
read num2
expr $num2 + 1 >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "输出的$num2不是整数请重新输入"
exit
fi
echo "请输入一个运算符:"
read o
case $o in
+)let "res=$num1+$num2"
echo "和为:"$res;;
-)let "res=$num1-$num2"
echo "差为:"$res;;

Guess you like

Origin blog.csdn.net/sincere_love/article/details/91360571