2011-08-18, 04:10(+02), Patrick:
On 17.08.2011 20:53, Stephane CHAZELAS wrote:
2011-08-17, 08:32(+02), Francky Leyn:
On 8/16/2011 10:53 PM, Stephane CHAZELAS wrote:
2) If VAR coincides with an environment variable, and in the
script I change it value, is this then propagated to outside
the script? Is the environment variable affected?
The environment is a list of strings (by convention of the format
[...]
In no circumstance are variable definitions in one process going
to affect the environment of other processes (an exception to
that is the "fish" shell)
Could it be that the two of you are not talking about the same thing?
Just for clarity: environment variables (henceforth "the environment")
of a process are (is) inherited by its children.
Everything is inherited by children, however upon executing a
command using the execve(2) system call, all the memory is
of a process is reinitialised. What the new command gets passed
along the execve(2) system call (as arguments) is a list of
arguments (argv) and a list of environment variables (envp).
As a side note though, that behavior didn't occur in the Bourne
shell. In the bourne shell, you had to explicitely export a
variable (even if the shell received itself in its environment),
for it to be exported to the commands executed by the shell.
$ VAR=foo sh -c 'VAR=bar; env' | grep VAR
VAR=foo
$ VAR=foo sh -c 'VAR=bar; export VAR; env' | grep VAR
VAR=bar