Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Jan 2016 19:32:39 -0900
From:      "CK" <nibbana@gmx.us>
To:        <freebsd-questions@freebsd.org>
Subject:   Sh-test, bug or not?
Message-ID:  <0LwGDy-1a6CqZ3TAs-0186MD@mail.gmx.com>

next in thread | raw e-mail | index | archive | help
If you have authoritative knowledge on the subject,
please state if this functionality is correct:

$ [ ! "" -a "" ] && echo pass || echo fail
pass
$ [ ! 11 -a "" ] && echo pass || echo fail
pass

The "-a" operator binds stronger than the "!" operator.
Intuition based on functionality in awk/C would suppose
that the "!" operator would bind stronger than the "-a"
operator, especially since "-a" does in fact have higher
precedence than the "-o" operator, as in awk/C.

In order to make it work as "expected", it gets ugly:

$ [ ! "" -a "" ] && echo pass || echo fail
pass
$ [ \( ! "" \) -a "" ] && echo pass || echo fail
fail

$ [ ! 11 -a "" ] && echo pass || echo fail
pass
$ [ \( ! 11 \) -a "" ] && echo pass || echo fail
fail

I never noticed this in 20 years, so I don't know if it always
worked this way, or if something changed in my upgrade from
4.11 to 9.3.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0LwGDy-1a6CqZ3TAs-0186MD>