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 <right-square-bracket> 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