我不认识这个运算符 $[],也找不到有关它的信息。但是我知道接下来的两个代码给出相同的输出
a=4
b=1
echo $[a-b] # => 3
和
a=4
b=1
echo $((a-b)) # => 3
那么 $[] 运算符的作用是什么,与 $(()) 有什么区别?
在我的 zsh shell 提示符中,当我打开其中任何一个并且没有关闭它们时,我已经编写了mathsubst。
最佳答案
阅读 man bash
表示旧格式 $[expression]
已弃用并将被删除。否则它们应该是等效的。
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.
关于bash - bash 中 $[a-b] 和 $((a-b)) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41081417/