在
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.