微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Bash脚本if语句

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.

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

原文地址:https://www.jb51.cc/bash/386465.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐