DASH Shell discussions
 help / color / mirror / Atom feed
From: Harald van Dijk <haraldvdijk@gmail.com>
To: dash <dash@vger.kernel.org>
Subject: Re: test incorrectly rejecting valid expression with confusing ! placement
Date: Mon, 26 Aug 2013 18:24:00 +0200	[thread overview]
Message-ID: <521B8120.8010407@gigawatt.nl> (raw)
In-Reply-To: <Pine.BSM.4.64L.1308261117200.19888@herc.mirbsd.org>

On 26/08/13 13:19, Thorsten Glaser wrote:
> Harald van Dijk dixit:
> 
>> $ src/dash -c 'test ! ! = !'
>> src/dash: 1: test: =: unexpected operator
>>
>> POSIX requires special behaviour for four-argument tests:
> 
> Right but…
> 
>> There are also some cases where test gives incorrect results when
>> combining ! with -o
> 
> … ‘-o’ is XSI, not POSIX. Do not expect…
>
>> $ src/dash -c 'test ! "" -o !'; echo $?
> 
> … this to work.
>
>> This is covered by the special rule for four arguments, there ! as the
>> first argument evaluates the remaining three-argument test and negates
>> the result. In this special case, ! does not have higher precedence than
>> -o, so the correct exit status is 1, which bash's test gives.
> 
> Only for a shell implementing the XSI ‘-o’ for POSIX test.

That is correct, but dash is such a shell. It attempts to implement -o,
-a, and \( ... \), and does so mostly correctly.

> You shouldn’t use -o anyway as it’s deprecated.

Indeed. I made a note that it has been obsoleted. I wrote:
> There are also some cases where test gives incorrect results when
> combining ! with -o, but ( ), -a and -o have been obsoleted in favour of
> the built-in shell operators ( ), && and ||, so I am not sure if that is
> worth fixing.

Even if it had not been obsoleted, it would be better not to use -a and
-o. In fact, I have trouble imagining why ! has not also been obsoleted
in favour of a simple logical negation of the test (test x != y instead
of test ! x == y, which is only possible for some of the tests), or the
shell's built-in ! (! test x == y instead of test ! x == y, which is
always possible).

Cheers,
Harald

  reply	other threads:[~2013-08-26 16:24 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 [this message]
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
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=521B8120.8010407@gigawatt.nl \
    --to=haraldvdijk@gmail.com \
    --cc=dash@vger.kernel.org \
    /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