我該如何讓這段代碼工作,以便乘以「*」和mod「%」不會得到錯誤信息?我在想是因爲它們對殼有特殊的意義。我將如何拿走它?Linux特殊shell的含義問題
#!/bin/bash
echo "Enter Number Operator Number"
echo "[Operators +, -, /, *, %]"
echo -n " ---> "
read num1 op num2
case $op in
+) printf "$num1 + $num2 = %d\n" `expr $num1 $op $num2`
;;
-) printf "$num1 - $num2 = %d\n" `expr $num1 $op $num2`
;;
/) printf "$num1/$num2 = %d\n" `expr $num1 $op $num2`
;;
\*) printf "$num1 * $num2 = %d\n" `expr $num1 $op $num2`
;;
%) printf "$num1 % $num2 = %d\n" `expr $num1 $op $num2`
;;
*) echo "Bad Operator: $op choose [+, -, *, /, %]"
;;
esac
引用所有變量,例如' 「$ OP」'。 – Barmar