Bash脚本if语句

前端之家收集整理的这篇文章主要介绍了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.f2er.com/bash/386465.html

猜你在找的Bash相关文章