bash [[ [a] == [a] ]] not true? square bracket affect compare result

后端 未结 2 698
夕颜
夕颜 2021-02-07 04:31

Anyone know why this happens? Is this a bug of bash?

x=\'mnt:[4026532411]\'

[[ $x == $x ]] && echo OK

I am expecting result OK

2条回答
  •  逝去的感伤
    2021-02-07 04:56

    What you are seeing is do do this sentence from the bash man page:

    When the == and != operators are used, the string to the right of the operator is considered a pattern and matched according to the rules described below under Pattern Matching, as if the extglob shell option were enabled.

    As you may already know, [...] in the shell allows matching from a group of characters. That is, given the files:

    $ ls
    fileA fileB fileC fileD
    

    Running ls file[AB] will yield:

    fileA fileB
    

    So in your expression, mnt:[1234] is interpreted in a similar fashion.

提交回复
热议问题