[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Inconsistent behavior between ! [ -a /bin/bash ] and [ ! -a /bin/ba
Re: Inconsistent behavior between ! [ -a /bin/bash ] and [ ! -a /bin/bash ]
Fri, 22 Feb 2002 19:34:07 -0500
Gnus/5.090006 (Oort Gnus v0.06) Emacs/20.7 (i386-redhat-linux-gnu)
> if ! [ -a /bin/bash ]; echo "bash not found"; fi
> if [ ! -a /bin/bash ]; echo "bash not found"; fi
> Both should produce no output, because of course I have bash,
> but the 2nd line prints "bash not found"
It looks like the "-a" argument is interpreted as the binary "and"
operator, and the "!" and "/bin/bash" are tested for being nonempty
strings, so the result is true. It's generally best to keep [ ]
expressions as simple as possible and move negations, ands, and ors
outside them, using "!", "&&", and "||". The parsing of [ ]
expressions is not always well-defined, and even when it is, it won't
necessarily be what you expect.