加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash:$[] vs. $(())

发布时间:2020-12-15 19:41:28 所属栏目:安全 来源:网络整理
导读:我刚刚绊倒了bash语法: foo=42bar=$[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
我刚刚绊倒了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.

所以$ […]是不再使用的旧语法。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读