编写shell脚本,实现两个变量之间的加减乘除运算。(if)

#! /usr/bin/bash
#±*/

a=0
b=0
op=0
result=0

read -p “Please input a:” a
read -p “Please input b:” b
read -p “Please input op:” op

if [ $op = “+” ]
then
result=expr $a + $b
echo $result
else if [ $op = “-” ]
then
result=expr $a + $b
echo $result
else if [ $op = “*” ]
then
result=expr $a + $b
echo $result
else if [ $op = “/” ]
then
result=expr $a + $b
echo $result
else
echo ‘error’
fi
fi
fi
fi

你可能感兴趣的:(shell)