我刚刚绊倒了bash语法:
foo=42 bar=$[foo+1] # evaluates an arithmetic expression
当我Googled为此,我发现http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html#sect_03_04_05:
3.4.6. Arithmetic expansion
Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is:
06001
…
Wherever possible,Bash users should try to use the Syntax with square brackets:
06002
However,this will only calculate the result of EXPRESSION,and do no tests…
在我的bash手册页中,我只能找到$((EXPRESSION))形式,如:
foo=42 bar=$((foo+1)) # evaluates an arithmetic expression
所以,使用$((…))的$ […]不执行什么测试,或者是$ […]只是旧版本的$((…))?
bash v3.2.48的联机帮助页面说:
[…] The format for arithmetic expansion is:
06000
The old format $[expression] is deprecated and will be removed in upcoming versions
of bash.
所以$ […]是不再使用的旧语法。