Joh*_*han 3 shell bash arithmetic
背后隐藏着什么奇怪的shell语法,它是$((40-35))如何计算值的?
例子:
$> echo $((40-35))
5
Run Code Online (Sandbox Code Playgroud)
bah*_*mat 15
从bash手册页:
Run Code Online (Sandbox Code Playgroud)((expression)) The expression is evaluated according to the rules described below under ARITHMETIC EVALUATION. If the value of the expres- sion is non-zero, the return status is 0; otherwise the return status is 1. This is exactly equivalent to let "expression".
并进一步:
Run Code Online (Sandbox Code Playgroud)Arithmetic Expansion Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is: $((expression))
任何放入双括号的东西都会成为一个bash可以求值的数学表达式。