bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistent behavior between ! [ -a /bin/bash ] and [ ! -a /bin/ba


From: Paul Jarc
Subject: Re: Inconsistent behavior between ! [ -a /bin/bash ] and [ ! -a /bin/bash ]
Date: Fri, 22 Feb 2002 19:34:07 -0500
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/20.7 (i386-redhat-linux-gnu)

cromwell@dp.2y.net wrote:
>       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.


paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]