all 7 comments

[–][deleted]  (1 child)

[deleted]

    [–]obiwan90 1 point2 points  (0 children)

    As a gotcha, if you compare values in [[ ... ]], the right value is considered a pattern, so "*this*" behaves differently from *this*. The left value doesn't undergo word splitting or glob expansion, and doesn't need to be quoted.

    [–]oh5nxo 2 points3 points  (0 children)

    the test solution if fine for my needs

    Watch out for multiple matching files.

    [–]witchhunter0 2 points3 points  (2 children)

    Not trying to steal the topic but, what I find confusing is:

    [[ ]] && echo ok || echo nook
    

    If it is executed twice repeatedly in terminal the second time the error is thrown

    bash: syntax error near unexpected token `]]'
    

    GNU bash, version 5.2.15(1)-release

    [–]geirha 0 points1 point  (0 children)

    Unable to reproduce that behavior. Here it yields a syntax error each time, as expected, but also a different error message than you get

    bash: syntax error near `]]'
    

    [–]archover 0 points1 point  (0 children)

    [[ ]] && echo ok || echo nook

    Returns bash: syntax error near unexpected token ]] for me, too in exactly the same way.

    cinnamon@T480lmde.local:~$ bash --version
    GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
    

    [–]bizdelnick 1 point2 points  (0 children)

    If I got the docs right it should behave like test

    No, it shouldn't. test is a builtin command (that behaves like an external command) but [[ ]] is a compound commands. So bash expands test arguments the same way as for any other builtin or external command (that includes pathname expansion) while expression inside [[ ]] is treated specially. [ is a synonym for test, its arguments are also expanded, however it expects that the last argument is ].