Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Sep 2016 05:56:06 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-bugs@FreeBSD.org
Subject:   [Bug 206295] sh(1)/test(1) bug (precedence)
Message-ID:  <bug-206295-8-LgMoKvvx9o@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-206295-8@https.bugs.freebsd.org/bugzilla/>
References:  <bug-206295-8@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D206295

--- Comment #3 from nibbana@gmx.us ---
I apologize for this somewhat incorrect statement (see below):

"this bizzare behavior only applies to the -a operator, not -o"

--

    the -a or -o indeed binds more strongly than the !.
    This is because -a and -o are explicitly said to be "binary
    primaries" and therefore '' -a ' ' matches the first case of
    3 arguments and !  '' -a '' matches the first case of
    4 arguments.

    In bash, dash, zsh and yash, [ !  "" -a "" ] likewise
    returns true.

    I recommend writing [ !  "" ] && [ "" ] or
    [ -z "" ] && [ -n "" ] instead.

--

Thanks for that reply: the fact that other shells do this is
important, and probably everything is working as it should,
but the manpage doesn't explain any of the logic.

The other justification is vague:

    This is because -a and -o are explicitly said to be "binary
    primaries" and therefore '' -a ' ' matches the first case of
    3 arguments and !  '' -a '' matches the first case of
    4 arguments.

'binary' only signifies that they are operators that require
two expressions and doesn't signify precedence over 'unary'
operators/primaries.  Whatever the case, it's a mess:

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

Accordingly, since the manpage explicitly states that -a has higher
precedence than -o, we should have "pass -o pass" above, but we get
"fail" instead.  At the very least, the manpage should state the
logic behind this ... is it:

(pass -o pass) -a fail =3D fail?
pass -o (pass -a fail) =3D fail?

--

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

pass -o (pass -a fail) =3D .....  no, this is not correct.
(pass -o pass) -a fail =3D fail?  -o has higher precedence than
                                   the 2nd -a ... which violates
                                   the specified manpage rule.

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

pass -o (fail -o fail) =3D .....  no, this is not correct.
(pass -o fail) -o fail =3D .....  no, this is not correct.

wtf???

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

pass -o (fail -a pass) =3D ..... no, this is not correct.
(pass -o fail) -a pass =3D ..... no, this is not correct.

wtf???

Is there any good reason for this matter to be
such a mess other than "family tradition?"
Did it make code more efficient in 1975?
It appears to be intentionally broken
without any rational basis whatsoever.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-206295-8-LgMoKvvx9o>