On Mär 27 2024, Greg Wooledge wrote: >> $ [ ! -a /tmp ] && echo ok || echo nok >> ok > > Here, you have three arguments, and argument 2 is a "binary primary" > (POSIX wording again), so it's treated as if you had written this: > > [ ! ] && [ /tmp ] && echo ok || echo nok > > This is simply performing two string length tests. Both strings are > non-empty (the first is one character, and the second is four), so > the result is true. > > The check for whether the first argument is '!' is not performed, > because the "$2 is a binary primary" check comes first. This is how > POSIX documents it.
FWIW, ksh parses it the other way round: $ ksh93 -c '[ ! -a /tmp ]; echo $?; [ . -a /tmp ]; echo $?; [ - -a /tmp ]; echo $?' 1 0 ksh93: [: -: unknown operator 2 -- Andreas Schwab, SUSE Labs, sch...@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."