两种shell算法的区别

两种shell算法的区别

下面两个shell算术命令有什么区别:

echo $[ $var1 - 1 ]
echo $(( $var1 - 1 ))

例如,假设 var1 = 5。

答案1

来自 man bash:

Arithmetic Expansion
   Arithmetic expansion allows the evaluation of an arithmetic 
   expression and the substitution of the result.  The format 
   for arithmetic expansion is:

          $((expression))

   The old format $[expression] is deprecated and will be 
   removed in upcoming versions of bash.

相关内容