Will the inherited environment variables be inherited as environment variables or as shell variables?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Say my bash shell have the following environment variable:
export a="Hello World"
If I executed a process from the bash shell, the a
environment variable will be inherited by this child process.
My question is: will a
be inherited by the child process as an environment variable or as a shell variable, that is, will a
in the child process be exported?
linux environment-variables
add a comment |Â
up vote
1
down vote
favorite
Say my bash shell have the following environment variable:
export a="Hello World"
If I executed a process from the bash shell, the a
environment variable will be inherited by this child process.
My question is: will a
be inherited by the child process as an environment variable or as a shell variable, that is, will a
in the child process be exported?
linux environment-variables
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Say my bash shell have the following environment variable:
export a="Hello World"
If I executed a process from the bash shell, the a
environment variable will be inherited by this child process.
My question is: will a
be inherited by the child process as an environment variable or as a shell variable, that is, will a
in the child process be exported?
linux environment-variables
Say my bash shell have the following environment variable:
export a="Hello World"
If I executed a process from the bash shell, the a
environment variable will be inherited by this child process.
My question is: will a
be inherited by the child process as an environment variable or as a shell variable, that is, will a
in the child process be exported?
linux environment-variables
linux environment-variables
asked Sep 24 '17 at 19:53
user7681202
237414
237414
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
As an environment variable.
This means that any child process that the child process starts will inherit the variable as well.
Testing:
$ export FOO=bar
$ sh
$ sh
$ sh
$ echo "$FOO"
bar
$ exit
$ exit
$ exit
Above, the shell creating the environment variable FOO
started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO
has the value bar
.
Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):
$ export FOO=bar
$ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
bar
quux
$ echo "$FOO"
bar
(in this example, it doesn't matter that FOO
is exported as ( ... )
subshells also inherit shell variables, but the the effect would have been the same had each ( ... )
been a totally separate process)
Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk
script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).
add a comment |Â
up vote
0
down vote
You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
As an environment variable.
This means that any child process that the child process starts will inherit the variable as well.
Testing:
$ export FOO=bar
$ sh
$ sh
$ sh
$ echo "$FOO"
bar
$ exit
$ exit
$ exit
Above, the shell creating the environment variable FOO
started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO
has the value bar
.
Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):
$ export FOO=bar
$ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
bar
quux
$ echo "$FOO"
bar
(in this example, it doesn't matter that FOO
is exported as ( ... )
subshells also inherit shell variables, but the the effect would have been the same had each ( ... )
been a totally separate process)
Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk
script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).
add a comment |Â
up vote
3
down vote
accepted
As an environment variable.
This means that any child process that the child process starts will inherit the variable as well.
Testing:
$ export FOO=bar
$ sh
$ sh
$ sh
$ echo "$FOO"
bar
$ exit
$ exit
$ exit
Above, the shell creating the environment variable FOO
started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO
has the value bar
.
Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):
$ export FOO=bar
$ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
bar
quux
$ echo "$FOO"
bar
(in this example, it doesn't matter that FOO
is exported as ( ... )
subshells also inherit shell variables, but the the effect would have been the same had each ( ... )
been a totally separate process)
Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk
script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
As an environment variable.
This means that any child process that the child process starts will inherit the variable as well.
Testing:
$ export FOO=bar
$ sh
$ sh
$ sh
$ echo "$FOO"
bar
$ exit
$ exit
$ exit
Above, the shell creating the environment variable FOO
started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO
has the value bar
.
Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):
$ export FOO=bar
$ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
bar
quux
$ echo "$FOO"
bar
(in this example, it doesn't matter that FOO
is exported as ( ... )
subshells also inherit shell variables, but the the effect would have been the same had each ( ... )
been a totally separate process)
Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk
script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).
As an environment variable.
This means that any child process that the child process starts will inherit the variable as well.
Testing:
$ export FOO=bar
$ sh
$ sh
$ sh
$ echo "$FOO"
bar
$ exit
$ exit
$ exit
Above, the shell creating the environment variable FOO
started a new interactive shell. That started another one, and that one started another one. Within this great-grandchild shell, $FOO
has the value bar
.
Another test showing that if if a subshell changes the environment variable, the change is carried over into later subshells (but is not propagated to the parent shells):
$ export FOO=bar
$ ( ( echo "$FOO"; FOO=quux; ( ( ( echo "$FOO" ) ) ) ) )
bar
quux
$ echo "$FOO"
bar
(in this example, it doesn't matter that FOO
is exported as ( ... )
subshells also inherit shell variables, but the the effect would have been the same had each ( ... )
been a totally separate process)
Note that environment variables are available to any process started from the shell, not just shell scripts. It would not make sense for a C program or awk
script to inherit them as shell variables as there is no concept of these kinds of variables in those languages (environment variables are strictly key-value pairs, whereas shell variables may be typed as integers, read-only, arrays, associative arrays, etc., depending on the capabilities of the shell).
edited Sep 24 '17 at 20:30
answered Sep 24 '17 at 20:04
Kusalananda
106k14209327
106k14209327
add a comment |Â
add a comment |Â
up vote
0
down vote
You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".
add a comment |Â
up vote
0
down vote
You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".
You can read your process environmental variables from /proc/PID/environ. So when you export variable, it is stated in this /proc "file".
answered Sep 24 '17 at 20:09
Jaroslav Kucera
4,3904621
4,3904621
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394189%2fwill-the-inherited-environment-variables-be-inherited-as-environment-variables-o%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password