我是 shell 脚本的新手。我在 shell 脚本中做一些数学问题,我发现几乎所有涉及数学的计算,除了 a 到 b (a^b)。
谁能告诉我我在这里做错了什么?
echo -n "enter op1 opr op2: "
read op1 opr op2
power()
{
value = $op2
a = $op1
if [ $value -eq o ]
then
echo "$op1 ^ $op2 = 1"
else
while [ $value -ne 1 ]
do
a = expr $a \* $op1
value =`expr $value - 1`
done
echo "$op1 ^ $op2 = $a"
fi
}
while [ "$op1" != "quit" ]
do
if [ $opr == "+" ]
then
echo " result: $op1 + $op2 = "`expr $op1 + $op2`
elif [ $opr == "-" ]
then
echo " result: $op1 - $op2 = "`expr $op1 - $op2`
elif [ $opr == "/" ]
then
echo " result: $op1 / $op2 = "`expr $op1 / $op2`
elif [ $opr == "x" ]
then
echo " result: $op1 x $op2 = "`expr $op1 \* $op2`
elif [ $opr == "^" ]
then
echo " result: $op1 ^ $op2 = "`expr $op1 ^ $op2`
else
echo " invalid operator ( + - x / )"
fi
echo -n "enter op1 opr op2: "
read op1 opr op2
done