相关疑难解决方法(0)

bash:$ [<arithmetic-expression>]与$((<arithmetic-expression>))

我刚刚偶然发现了bash语法:

foo=42
bar=$[foo+1] # evaluates an arithmetic expression
Run Code Online (Sandbox Code Playgroud)

当我用Google搜索时,我找到了 http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html#sect_03_04_05:

3.4.6.算术扩展

算术扩展允许评估算术表达式和结果的替换.算术扩展的格式是:

$(( EXPRESSION )) 
Run Code Online (Sandbox Code Playgroud)

...

只要有可能,Bash用户应尝试使用方括号的语法:

$[ EXPRESSION ] 
Run Code Online (Sandbox Code Playgroud)

但是,这只会计算EXPRESSION的结果,并且不进行测试......

在我的bash手册页中,我只能找到如下$(( EXPRESSION ))形式:

foo=42
bar=$((foo+1)) # evaluates an arithmetic expression
Run Code Online (Sandbox Code Playgroud)

那么什么测试不是用$[...]那个做的$((...)),或者$[...]只是遗留版本$((...))

legacy syntax bash arithmetic-expressions operators

29
推荐指数
2
解决办法
6257
查看次数

标签 统计

arithmetic-expressions ×1

bash ×1

legacy ×1

operators ×1

syntax ×1