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
Subject: Re: test incorrectly rejecting valid expression with confusing ! placement
Date: Tue, 03 Sep 2013 20:38:16 -0600	[thread overview]
Message-ID: <52269D18.3090200@redhat.com> (raw)
In-Reply-To: <20130904015629.GA19007@gondor.apana.org.au>

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

On 09/03/2013 07:56 PM, Herbert Xu wrote:
> Harald van Dijk <harald@gigawatt.nl> wrote:
>> Hi,
>>
>> Now that Herbert fixed the reported crash in test (in a far simpler
>> manner than I had suggested, which I like), I did some more testing, and
>> came across one case that does not currently work, and did not work in
>> the past, but is perfectly valid:
>>
>> $ src/dash -c 'test ! ! = !'
>> src/dash: 1: test: =: unexpected operator
> 
> Agreed.
>  
>> $ src/dash -c 'test ! -o !'
>> src/dash: 1: test: -o: unexpected operator
> 
> Nope, the rule is quite clear that it only applies to binary
> primaries, not operators.  -o is an operator.

Huh?
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
states that there are only two operators "!" and "()", and specifically
mentions that -a and -o are binary primaries:

expression1 -a  expression2
    [OB XSI] [Option Start]
    True if both expression1 and expression2 are true; otherwise, false.
The -a binary primary is left associative. It has a higher precedence
than -o. [Option End]
expression1 -o  expression2
    [OB XSI] [Option Start]
    True if either expression1 or expression2 is true; otherwise, false.
The -o binary primary is left associative. [Option End]

"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.

-- 
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  2:39 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 [this message]
2013-09-04  3:20     ` Herbert Xu
2013-09-04  5:03       ` Herbert Xu
2013-09-04 12:09         ` Eric Blake
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=52269D18.3090200@redhat.com \
    --to=eblake@redhat.com \
    --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