Re: [NOTABUG] false positive: [ ! -o optname ]

2016-09-25 Thread Thorsten Glaser
Martijn Dekker dixit:

>Makes complete sense and I should have figured this out myself. Sorry
>for the noise and thanks for the references.

Oh well, others can still learn from it. (Note that -o for option is
also not POSIX, but POSIX rules still apply, and [[…]] doesn’t have
this problem.)

>I guess this explains why the POSIX spec does not include 'test -o' (or
>'test -a' as a synonym for 'test -e'). Not including them avoids this
>logical but unintuitive behaviour.

That, and it specificially says their spec is unambiguous only
because they require the argument for -t.

bye,
//mirabilos
-- 
Stéphane, I actually don’t block Googlemail, they’re just too utterly
stupid to successfully deliver to me (or anyone else using Greylisting
and not whitelisting their ranges). Same for a few other providers such
as Hotmail. Some spammers (Yahoo) I do block.


Re: [NOTABUG] false positive: [ ! -o optname ]

2016-09-25 Thread Martijn Dekker
Op 25-09-16 om 22:52 schreef Thorsten Glaser:
> Per XSI, -o is a binary primary:
[...]
> Well, $1 is '!' and therefore true. Same for $3, which is
> 'noclobber' and therefore true. That means that the result
> of -o is also true.

Makes complete sense and I should have figured this out myself. Sorry
for the noise and thanks for the references.

I guess this explains why the POSIX spec does not include 'test -o' (or
'test -a' as a synonym for 'test -e'). Not including them avoids this
logical but unintuitive behaviour.

- M.



Re: [NOTABUG] false positive: [ ! -o optname ]

2016-09-25 Thread Thorsten Glaser
Martijn Dekker dixit:

>   [ ! -o noclobber ]
>
>amounts to a no-op, always returning exit status 0.

This is the same as:

test ! -o noclobber

POSIX says:

 The  algorithm  for  determining  the  precedence of the operators
 and the return value that shall be generated is based on the
 number of arguments presented to test. (However, when using the
 "[...]" form, the  final argument shall not
 be counted in this algorithm.)

 In the following list, $1, $2, $3, and $4 represent the arguments
 presented to test:

We have three arguments ($1 = '!', $2 = '-o', $3 = 'noclobber'):

   3 arguments:
  + If $2 is a binary primary, perform the binary test of $1
and $3.

Per XSI, -o is a binary primary:

   expression1 -o  expression2
  ^[[9]OB XSI] [Option Start]
  True  if  either  expression1  or expression2 is true;
  otherwise, false. The -o binary primary is left associative.
  [Option End]

So we perform a test on $1:

   1 argument:
  Exit true (0) if $1 is not null; otherwise, exit false.

Well, $1 is '!' and therefore true. Same for $3, which is
'noclobber' and therefore true. That means that the result
of -o is also true.

>Interestingly, the original pdksh does not have this bug, but bash has
>it.

That’s because the original pdksh has this bug and both mksh
and GNU bash have been changed to adhere to POSIX plus XSI
(for -a and -o) by the letter.

bye,
//mirabilos
-- 
“It is inappropriate to require that a time represented as
 seconds since the Epoch precisely represent the number of
 seconds between the referenced time and the Epoch.”
-- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2