bug-bash
[Top][All Lists]
Advanced

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

Re: handling of test == by BASH's POSIX mode


From: Dan Douglas
Subject: Re: handling of test == by BASH's POSIX mode
Date: Sun, 27 May 2012 06:24:08 -0500
User-agent: KMail/4.8.3 (Linux/3.4.1-pf+; KDE/4.8.3; x86_64; ; )

On Sunday, May 27, 2012 08:45:46 PM Jon Seymour wrote:
> On 27/05/2012, at 17:39, Geir Hauge <geir.hauge@gmail.com> wrote:
> 
> > 2012/5/27 Jon Seymour <jon.seymour@gmail.com>:
> >> Is there a reason why bash doesn't treat == as an illegal test
> >> operator when running in POSIX mode?
> > 
> > POSIX does not say == is not allowed.
> > 
> > POSIX tells you what the shell should at least be able to do. A POSIX
> > compliant shell can have whatever other features it likes, as long as
> > the POSIX features are covered.
> > 
> 
> I guess the question is better phrased thus: what use case is usefully 
served by having bash's POSIX mode support a superset of test operators than 
other compliant POSIX shells?  As it stands, I can't use bash's POSIX mode to 
verify the validity or otherwise of a POSIX script because bash won't report 
these kinds of errors - even when running in POSIX mode.
> 
> There is an --enable-strict-posix (?) configuration option. Will this do what 
I expect?
> 
> > 
> >> This is problematic because use of test == in scripts that should be
> >> POSIX isn't getting caught when I run them under bash's POSIX mode.
> >> The scripts then fail when run under dash which seems to be stricter
> >> about this.
> > 
> > Don't use non-POSIX features in a POSIX script, and you'll be fine.
> > http://www.opengroup.org/onlinepubs/9699919799/utilities/contents.html
> > 
> 
> Which is the exactly the point. Practically speaking when I write scripts I 
expect an interpreter that claims to be running in POSIX mode to give me some 
help to flag usage of non POSIX idioms. Yes, I can second guess the interpreter 
by reading the spec, but is this really the most efficient way to catch these 
kinds of errors?
> 
> Jon.

There are no shells in existence that can do what you want. All major shells 
claiming to be POSIX compatible include some superset that can't be disabled. 
The only shell I have installed not supporting == in [ is dash, and there are 
so many scripts in the wild using == with [ it would be a miracle if your 
system didn't break because of it. Even the coreutils /usr/bin/[ supports ==.

Performing that kind of checking, rigorously, in a shell, would be impossible 
to do statically anyway. Any such lint tool is limited to lexical analysis 
which makes it not very useful for testing unless your script is perfectly 
free of side-efffects. And who writes side-effect free shell scripts?

How would the shell check for the correctness of:

"$(rm -rf somepath; echo '[')" x == x ]
-- 
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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