假設我有以下代碼bash腳本
for n in {50..300};
do
((a = 0.3*$n))
#do something
echo $n
echo $a
done
當我運行的代碼,我收到一個錯誤,它說 ((: a = 0.3*50: syntax error: invalid arithmetic operator (error token is ".3*50")
我知道那一定是因爲0.3或任何十進制號碼是不可識別的,或者可能是由於某些格式問題,因爲我以前嘗試((a = $n/2))
哪些工作正常,非常感謝,如果任何人都可以給我一個提示。
複製http://stackoverflow.com/questions/3279932/bash-multiplying-decimal-to-int – Nasr