[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "sh -a" sets the POSIXLY_CORRECT *environment* variable
From: |
Chet Ramey |
Subject: |
Re: "sh -a" sets the POSIXLY_CORRECT *environment* variable |
Date: |
Thu, 16 Aug 2018 10:33:06 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
On 8/15/18 3:23 PM, Stephane Chazelas wrote:
> 2018-08-15 11:05:06 -0400, Chet Ramey:
>> On 8/14/18 11:50 AM, Stephane Chazelas wrote:
>>> Hi,
>>>
>>> This is from
>>> https://unix.stackexchange.com/questions/462333/why-does-a-in-bin-sh-a-affect-sed-and-set-a-doesnt
>>> (original investigation by Mark Plotnick)
>>>
>>> Though not documented, enabling the POSIX mode in bash whether
>>> with
>>>
>>> - bash -o posix
>>> - sh
>>> - env SHELLOPTS=posix bash
>>> - set -o posix # within bash
>>>
>>> causes it to set the value of the $POSIXLY_CORRECT shell
>>> variable to "y" (if it was not already set)
>>
>> Yes. This behavior dates from early 1997. It was put in on request so users
>> could get a posix environment from the shell, since GNU utilities
>> understand the POSIXLY_CORRECT variable. I could improve the documentation
>> there, but a 20-plus-year-old feature isn't going to change.
> [...]
>
> Maybe there was a misunderstanding.
>
> It's fine that bash enters POSIX mode when $POSIXLY_CORRECT is
> set. IOW, it's fine that bash enters POSIX mode when the users
> request it.
>
> The problem I'm trying to raise is about the reverse behaviour:
> that bash takes upon itself to request POSIX mode of all other
> utilities when it itself enters POSIX mode, that it sets
> $POSIXLY_CORRECT when it enters POSIX mode.
You're commingling two separate issues.
I explained the first one yesterday: that bash, back in 1997, added
setting POSIXLY_CORRECT when turning on Posix mode as the result of
requests to support the `standard' GNU mechanism for indicating POSIX
behavior.
This, in itself, is benign: it still requires that a user export the
variable for utilities to inherit whatever POSIX-specific behavior they
implement.
This is a `problem' only when you combine it with the other issue: the
rarely-used `allexport' option and which variables get auto-exported. I
haven't weighed in on that one, but I am inclined to say that allexport
covers all the variables a shell sets internally, whether ones like
POSIXLY_CORRECT or IGNOREEOF that indicate settings, or ones that are
set as side effects of builtins like `read' and `getopts'.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/