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

Bash脚本if语句

发布时间:2020-12-15 18:49:44 所属栏目:安全 来源:网络整理
导读:在 Bash脚本中,以下片段有什么区别? 1)使用单括号: if [ "$1" = VALUE ] ; then # codefi 2)使用双括号: if [[ "$1" = VALUE ]] ; then # codefi The [[ ]] construct is the more versatile Bash version of [ ]. This is the extended test command,ado
在 Bash脚本中,以下片段有什么区别?

1)使用单括号:

if [ "$1" = VALUE ] ; then
 # code
fi

2)使用双括号:

if [[ "$1" = VALUE ]] ; then
 # code
fi

The [[ ]] construct is the more versatile Bash version of [ ]. This is the extended test command,adopted from ksh88.

Using the [[ … ]] test construct,rather than [ … ] can prevent many logic errors in scripts. For example,the &&,||,<,and > operators work within a [[ ]] test,despite giving an error within a [ ] construct.

More info on the Advanced Bash Scripting Guide.

在您的代码段中,没有任何区别,因为您没有使用任何其他功能.

(编辑:李大同)

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

    推荐文章
      热点阅读