[Zope-dev] Moving forward with Zope 2.7

R. David Murray bitz@bitdance.com
Tue, 26 Nov 2002 11:06:48 -0500 (EST)


On Tue, 26 Nov 2002, Tino Wildenhain wrote:
> Tried it:
>
> >>> os.environ['MYENVIRON']='FooBar'
> ^D
>
> echo $MYENVIRON
>
> ^^^^ nothing.
>
> What is wrong?

rdmurray@stage:~>cat temp.sh
export TEST='abc'
echo $TEST
rdmurray@stage:~>sh temp.sh
abc
rdmurray@stage:~>echo $TEST

^^^^^ equally nothing.

export (and the equivalent python above) sets the environment
variable in the current process environment space, *not* the parent
(that's a *much* trickier operation).  The obverse (TEST='abc'
somecommandhere) sets the environment variable only in the *sub*process
environment space (the one being created) and does not affect the
current process.  The python equivalent of *that* would be to supply
a modified *copy* of the ENVIRON dict to execve or similar.

To do the python equivalent of what happens when you set a variable
in a script *without* using export (the current process environment
is changed but the change is not passed to subprocesses), you'd
have to make a copy of the environ before modifying it, and pass
*that* to execve or equivalent.

--RDM