Meaning of double square brackets in bash

This question already has an answer here:

  • Difference between single and double square brackets in Bash 6 answers

  • [[ is a much more versatile version of [ in bash.

    For example, 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.

    also, their implementations are different

    -bash-3.2$ type [
    [ is a shell builtin
    -bash-3.2$ type [[
    [[ is a shell keyword
    

    Refer here for a good explanation


    [[ ]] are equal to test keyword.

    You can also use [ ] but [[ ]] isn't compatible with all shell types

    To me, if I understand the real sense of question, question itself isn't well-formulated.
    Those brackets have to be here not so much for order determination, but because the bash synopsis require them

    Edit

    Question is changed, so my answer too.

    [[ ]] is used against [ ] because you don't have to worry about quoting the left hand side of the test that will be read as a variable.
    Moreover, < and > doesn't need to be escaped

    链接地址: http://www.djcxy.com/p/17476.html

    上一篇: 如何在shell脚本中检查目录是否存在?

    下一篇: 双方括号在bash中的含义