bug-bash
[Top][All Lists]
Advanced

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

Re: variable set in exec'ing shell cannot be unset by child shell


From: Chet Ramey
Subject: Re: variable set in exec'ing shell cannot be unset by child shell
Date: Mon, 16 Oct 2023 11:42:38 -0400
User-agent: Mozilla Thunderbird

On 10/14/23 12:03 PM, Robert Elz wrote:

However in the case of a special built-in utility (which "." is) then
the requirements are much stricter:

   � If the command name is a special built-in utility, variable assignments
     shall affect the current execution environment before the utility is
     executed and remain in effect when the command completes; if an assigned
     variable is further modified by the utility, the modifications made by
     the utility shall persist. Unless the set -a option is on (see set),
     it is unspecified:

       -- Whether or not the variables gain the export attribute during the
          execution of the special built-in utility

       -- Whether or not export attributes gained as a result of the variable
          assignments persist after the completion of the special built-in
          utility

That is, in the case of "VAR=val . script" (which is what the OP was doing,
there were no functions involved) POSIX actually requires that VAR=val be
done before the utility is invoked (and never undone) and that if the script
modifies VAR, that modification remain after it has completed.

Special builtins are a POSIX concept, and bash conforms to POSIX when in
posix mode. It doesn't treat special builtins differently when not in
posix mode.


Note that some of that text is new in Issue 8, to deal with making it
clear what happens if a script does "X=Y unset X" where previously it
might have seemed permitted for X to remain set after that command (to Y
or whatever value it had before) - now it is (will be) clear that is not
permitted, and X must be unset after that command completes.

Bash doesn't do this yet in posix mode, but it will eventually.

--
``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/




reply via email to

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