bug-bash
[Top][All Lists]
Advanced

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

Re: initialisation bash variables


From: Patrick
Subject: Re: initialisation bash variables
Date: Wed, 28 Mar 2012 18:26:01 -0000
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11

On 18.08.2011 10:39, Stephane CHAZELAS wrote:
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).
Right. I missed the fact, that the environment is not *necessarily* inherited.

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
Interresting! I do not have the bourne shell installed. Bash tries to mimic it when called as "sh", but it does not produce the "correct" result for your first example. Not that I would mind about that though. Busybox btw. also yields "VAR=bar". Phew... Dash as well. There is no "sh" package in the ubuntu repos. Google also has no quick answer. What kind of "sh" are you actually using if I may ask ?


reply via email to

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