Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Builtin test and parsing of conditionals
On Wed, 04 Sep 2013 09:15:03 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> According to some discussion on the austin-group (POSIX) mailing list,
> the following:
>
> test ! -a !
> test ! -o !
> test ! = !
>
> should all be parsed as comparing the string "!" to the string "!", but
> zsh gets this right only in the last case.
I don't understand that. -a means "and" and -o means "or", unless
they're being interpreted as strings, but I don't see how that could be
if ! is supposed to be interpreted as a string. So where does the
implicit comparison come from? If -a were taken as high precedence you
might read it as
test -n ! -a n !
test -n ! -a n !
which is how
test foo -a bar
test foo -o bar
are interpreted, which you can see by
test foo -a '' # false
test foo -o '' # true
... same if you omit the ''.
(Outside our control, but I imagine people aren't daft enough to rely on
this sort of behaviour in new scripts...?)
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author