I want to clarify a confusion I am having in shell variable vs environment variable. I did the following test, where I have a shell variable abc
and export
it to an environment variable.
$
$ abc="shell var"
$ env | grep abc
$ echo $abc
shell var
$ export abc="env var"
$ env | grep abc
abc=env var
$ echo $abc
env var
$ unset abc
$ env | grep abc
$ echo $abc
$
After the export is done, I try to echo $abc
.
Questions:
Does export move the variable
abc
from shell to the environment OR does it create a copy in the environment and assign it a new value ?When the second
echo
is done after theexport
, doesecho
check ifabc
is in environment and then print it, OR hasabc
been completely removed from the shell and is only present in the environment which is whyecho
prints its value ?
export abc="env var"
, does that mean : change the value for this shell variable, but also mark this for export ? I guess that's whyecho $abc
printsenv var
still being in the shell process ? – Jake Aug 13 '15 at 05:05export abc="env var"
does the assignment and marks the variable for export all in one step. Also, I added to the answer an example of a "variable exported for the command." – John1024 Aug 13 '15 at 05:08SHELL
is managed directly by the shell. The shell manages many such variables. For a full list of shell such variables set by bash, look inman bash
for the section entitled "Shell Variables". – John1024 Aug 13 '15 at 07:09