shell脚本----简单计算器

read -p "请输入一个数:" a;
read -p "请输入一个算法:" b;
read -p "请输入一个数:" c;
#加法:
if [ "$b" == "+" ] ; then
   sum=$(expr $a + $c);
   echo "$a+$c=$sum"
fi
#减法:
if [ "$b" == "-" ] ; then
    sum=$(expr $a - $c);
    echo "$a-$c=$sum"
fi
#乘法:
if [ "$b" == "*" ] ; then
    sum=$(expr $a \* $c);
    echo "$a*$c=$sum"
fi
#除法:
if [ "$b" == "/" ] ; then
    sum=$(expr $a / $c);
    echo "$a/$c=$sum"
fi
#取余:
if [ "$b" == "%" ] ; then
    sum=$(expr $a % $c);
    echo "$a%$c=$sum"
fi

你可能感兴趣的:(shell)