[adding the Austin Group] On 09/03/2013 11:03 PM, Herbert Xu wrote: > On Wed, Sep 04, 2013 at 01:20:00PM +1000, Herbert Xu wrote: >> >>> "test ! -o !" is a three-argument test, where $2 (-o) is a binary >>> primary, so it is the binary test of $1 and $3, and the end result is an >>> exit status of 0. Bash and ksh get it right, dash fails. >> >> Both zsh and posh do it like dash: >> >> $ zsh -c 'test ! -o !'; echo $? >> zsh:test:1: too many arguments >> 1 >> $ zsh -c 'test ! = !'; echo $? >> 0 >> $ > > Another case in point is 'test ! = -o a', here bash differs with > every other shell installed on my system, which all return 0, just > like dash. GNU coreutils behaves like bash; the POSIX wording justifies bash: 4 arguments: If $1 is '!', negate the three-argument test of $2, $3, and $4. [OB XSI] [Option Start] If $1 is '(' and $4 is ')', perform the two-argument test of $2 and $3. [Option End] On systems that do not support the XSI option, the results are unspecified if $1 is '(' and $4 is ')'. Otherwise, the results are unspecified. That is, "test ! = -o a" should be parsed as "test ! \( = -o a \)" (bash's behavior, per the first bullet), not "test \( ! = \) -o a" (ksh's behavior, per the third bullet). Yet another reason why the XSI -a and -o make the parsing precedence of test a pain to decipher. Do we need to open yet another bug against POSIX to allow for ksh's behavior? -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature