I agree. Also, not sure what's being improved. I also would have expected to run into a reference of double and single brackets used in if statements, e.g. [[ ]] and [ ] -- which I always seem to find confusing.
so you can do things like
[[ 1 < 2 ]] && echo true # where < is now not redirect, like to (( 1 < 2 ))
[[ "x" == 'y' || x == x ]] # note how || is not behaving the same as [ '' || 'y' ]
`man 1 test` explains the more conventional `[ ]` where the bash man page would better explain the [[ case.Here it is in pdksh:
# [ "Z" == "z" ] && echo Bob
# [ "Z" == "Z" ] && echo Bob
Bob
I chose pdksh on purpose - because _it_ also supports [[ (builtin like bash)[2], so while [[ is a "bash-ism" it's actually present in some/many other shells as well. However, the operational aspect is not identical between [ and [[, both in the bash and pdksh implementations and let's add zsh to show the same line of shell break: # [[ "Z" == "Z" && "A" == "A" ]] && echo Bob
Bob
# [ "Z" == "Z" && "A" == "A" ] && echo Bob
pdksh: [: missing ]
# [[ "Z" == "Z" && "A" == "A" ]] && echo Bob
Bob
# [ "Z" == "Z" && "A" == "A" ] && echo Bob
-bash: [: missing `]'
# [[ "Z" == "Z" && "A" == "A" ]] && echo Bob
Bob
# [ "Z" == "Z" && "A" == "A" ] && echo Bob
zsh: = not found
The [ operator requires that you use the bash/pdksh method to combine them with && "outside the brackets" in a more POSIX like use, like so: # if ([ "Z" == "Z" ] && [ "A" == "A" ]); then echo Bob; fi;
Bob
...except on zsh, because (surprise!) zsh has decided to internalize the [ command rather than use the external one (which works OK); but it also has a problem with the "=" sign being used like this[3] with the test operator. zsh requires we then handle the == sign by quoting it (or unsetting a value internally): # if [ "Z" == "Z" ] && [ "A" == "A" ]; then echo Bob; fi;
zsh: = not found
# if [ "Z" '==' "Z" ] && [ "A" '==' "A" ]; then echo Bob; fi;
Bob
This last example is a subtle point - the use of [[ is actually _more_ compatible between bash/pdksh/zsh than the use of [ due to the way zsh handles the input which is different than bash/pdksh and even old school POSIX Bourne shell (/bin/sh).This got kinda long sorry, hope it helps.
[1] there's actually a binary "[" and a binary "test" in the `coreutils` package on most systems, however I'm not sure why they have different binary file sizes to be honest
[2] https://linux.die.net/man/1/pdksh search "[["