bug-bash
[Top][All Lists]
Advanced

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

Re: Q on Bash's self-documented POSIX compliance...


From: Chet Ramey
Subject: Re: Q on Bash's self-documented POSIX compliance...
Date: Sun, 27 Jan 2013 17:50:58 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 1/26/13 3:27 PM, Linda Walsh wrote:
> I noted on the bash man page that it says it will start in posix compliance
> mode when started as 'sh' (/bin/sh).

While that's true, I think you're not reading far enough about posix mode.
The man page and description of `set -o posix' say:

"Change the behavior of bash where the default operation differs
from the POSIX standard to match the standard."

This just means that bash's default differs from what Posix specifies in
certain areas, and posix mode changes those behaviors.  It doesn't say
anything about disabling features Posix doesn't mention or leaves
unspecified.

> What does that mean about bash extensions like arrays and
> use of [[]]?

Nothing; they work like they do when not in posix mode.

> If you operate in POSIX compliance mode, what guarantee is there that
> you can take a script developed with bash, in POSIX compliance mode,
> and run it under another POSIX compliant shell?

There's a good chance that you will be able to move scripts between
different shells asserting Posix conformance, but you have to restrict the
parts of the shell language you use to those Posix specifies.

> Is it such that Bash can run POSIX compliant scripts, BUT, cannot be
> (easily) used to develop such, as there is no way to tell it to
> only use POSIX?

You have to use the standard to figure out what is Posix and what isn't.
Bash doesn't turn off features that Posix doesn't specify when in Posix
mode.

> If someone runs in POSIX mode, should bash keep arbitrary bash-specific
> extensions enabled?

Yes, it does.

> I am wondering about the rational, but also note that some people believe
> they are running a POSIX compatible shell when they use /bin/sh, but would
> get rudely surprised is another less feature-full shell were dropped in
> as a replacement.

That's a different question.  Both shells can conform to Posix, but offer
different features beyond it or different implementation choices for things
Posix leaves unspecified.

There are different shells with different degrees of feature availability
beyond what Posix specifies.  I usually use dash, ksh93, and bash to decide
questions about exactly what Posix means and doesn't mean.  There is also
`posh', which is even stricter about Posix than dash, but kind of weird
(it throws an error if you run `exit' without an argument, for instance).

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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