DASH Shell discussions
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Herbert Xu <herbert@gondor.hengli.com.au>
Cc: Harald van Dijk <harald@gigawatt.nl>,
	dash@vger.kernel.org, Austin Group <austin-group-l@opengroup.org>
Subject: Re: test incorrectly rejecting valid expression with confusing ! placement
Date: Wed, 04 Sep 2013 06:09:31 -0600	[thread overview]
Message-ID: <522722FB.5040702@redhat.com> (raw)
In-Reply-To: <20130904050323.GA20305@gondor.apana.org.au>

[-- Attachment #1: Type: text/plain, Size: 1590 bytes --]

[adding the Austin Group]

On 09/03/2013 11:03 PM, Herbert Xu wrote:
> On Wed, Sep 04, 2013 at 01:20:00PM +1000, Herbert Xu wrote:
>>  
>>> "test ! -o !" is a three-argument test, where $2 (-o) is a binary
>>> primary, so it is the binary test of $1 and $3, and the end result is an
>>> exit status of 0.  Bash and ksh get it right, dash fails.
>>
>> Both zsh and posh do it like dash:
>>
>> $ zsh -c 'test ! -o !'; echo $?
>> zsh:test:1: too many arguments
>> 1
>> $ zsh -c 'test ! = !'; echo $?
>> 0
>> $
> 
> Another case in point is 'test ! = -o a', here bash differs with
> every other shell installed on my system, which all return 0, just
> like dash.

GNU coreutils behaves like bash; the POSIX wording justifies bash:

4 arguments:

        If $1 is '!', negate the three-argument test of $2, $3, and $4.

        [OB XSI] [Option Start] If $1 is '(' and $4 is ')', perform the
two-argument test of $2 and $3. [Option End]  On systems that do not
support the XSI option, the results are unspecified if $1 is '(' and $4
is ')'.

        Otherwise, the results are unspecified.

That is, "test ! = -o a" should be parsed as "test ! \( = -o a \)"
(bash's behavior, per the first bullet), not "test \( ! = \) -o a"
(ksh's behavior, per the third bullet).

Yet another reason why the XSI -a and -o make the parsing precedence of
test a pain to decipher.  Do we need to open yet another bug against
POSIX to allow for ksh's behavior?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

  reply	other threads:[~2013-09-04 12:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-24 14:01 test incorrectly rejecting valid expression with confusing ! placement Harald van Dijk
2013-08-26 11:19 ` Thorsten Glaser
2013-08-26 16:24   ` Harald van Dijk
2013-09-04  1:56 ` Herbert Xu
2013-09-04  2:38   ` Eric Blake
2013-09-04  3:20     ` Herbert Xu
2013-09-04  5:03       ` Herbert Xu
2013-09-04 12:09         ` Eric Blake [this message]
2014-09-28 10:42   ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=522722FB.5040702@redhat.com \
    --to=eblake@redhat.com \
    --cc=austin-group-l@opengroup.org \
    --cc=dash@vger.kernel.org \
    --cc=harald@gigawatt.nl \
    --cc=herbert@gondor.hengli.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox