DASH Shell discussions
 help / color / mirror / Atom feed
* test incorrectly rejecting valid expression with confusing ! placement
@ 2013-08-24 14:01 Harald van Dijk
  2013-08-26 11:19 ` Thorsten Glaser
  2013-09-04  1:56 ` Herbert Xu
  0 siblings, 2 replies; 9+ messages in thread
From: Harald van Dijk @ 2013-08-24 14:01 UTC (permalink / raw)
  To: dash

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-09-28 10:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-09-28 10:42   ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox