Linux-Dash Archive mirror
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: dash <dash@vger.kernel.org>
Subject: test incorrectly rejecting valid expression with confusing ! placement
Date: Sat, 24 Aug 2013 16:01:17 +0200	[thread overview]
Message-ID: <5218BCAD.2010107@gigawatt.nl> (raw)

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

POSIX requires special behaviour for four-argument tests:

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

so this is supposed to evaluate as the negation of test ! = !. That test
does work properly in dash.

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. Details anyway:

$ src/dash -c 'test ! -o !'
src/dash: 1: test: -o: unexpected operator

This is covered by the special rule for three arguments, where the
second argument is a binary operator. -o is a boolean binary operator,
but a binary operator nonetheless, so this should test whether the two !
arguments are empty strings.

$ src/dash -c 'test ! "" -o !'; echo $?
0

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.

Cheers,
Harald

             reply	other threads:[~2013-08-24 14:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-24 14:01 Harald van Dijk [this message]
2013-08-26 11:19 ` test incorrectly rejecting valid expression with confusing ! placement 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
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=5218BCAD.2010107@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).