Shell

shell程式語法錯誤

  • April 6, 2021
num1 = 20
num2 = 20

echo $(( num1 + num2 ))
echo $(( num1 - num2 ))
echo $(( num1 * num2 ))
echo $(( num1 / num2 ))
echo $(( num1 % num2 ))

錯誤 :

./practice.sh: line 53: num1: command not found
./practice.sh: line 54: num2: command not found
0
0
0
./practice.sh: line 59: num1 / num2 : division by 0 (error token is "num2 ")
./practice.sh: line 60: num1 % num2 : division by 0 (error token is "num2 ")

我錯過了什麼?當我嘗試一些數字而不是num1num2內部迴聲時。我注意到它列印正確..但是,這裡發生了什麼..?

num1=20
num2=20

當我嘗試從 num1 和 num2 中刪除空格時。我注意到它正在工作

引用自:https://unix.stackexchange.com/questions/643719