bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash incompatible with sh,maybe this is a bug


From: Eric Blake
Subject: Re: bash incompatible with sh,maybe this is a bug
Date: Wed, 26 Dec 2007 04:10:46 +0000

> > [  !  "$test"  -a "$test1"  ] && test="papa";
> 
> This is a test with four arguments, thus the rules are:
> 
>   • If $1 is ’!’, negate the three-argument test of $2, $3, and $4.
>   • If $1 is ’(’ and $4 is ’)’, perform the two-argument test of $2 
> and $3.
>   • Otherwise, the results are unspecified.
> 
> Since "$test" -a "$test1" is false, the test comes out as true.
> 
> Using test with a combination of more than one primary operator is not
> recommended.

Actually, the Austin group agreed that the combination of ! and -a is
inherently ambiguous, as it can either be parsed '( ! $test ) -a $test1'
or '! ( $test -a $test1 )' according to the rules quoted above.
See this interpretation from last year:
http://www.opengroup.org/austin/interps/uploads/40/10043/AI-107.txt

> 
> > I think ,this is a bug in bash.and i test it on many freebsd release 4.11,
> > 6.1,6.2 with default bash version,this is same.
> 
> Your /bin/sh is not POSIX compliant.

Actually, your /bin/sh very well could be POSIX compliant - you just
happened to pick an example that POSIX doesn't nail down, and which
is therefore unportable and should not be used.  Not to mention that
[ $test1 -a $test2 ] is an XSI extension, so your shell need not support
it to begin with.

-- 
Eric Blake




reply via email to

[Prev in Thread] Current Thread [Next in Thread]