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
abcfrom shell to the environment OR does it create a copy in the environment and assign it a new value ?When the second
echois done after theexport, doesechocheck ifabcis in environment and then print it, OR hasabcbeen completely removed from the shell and is only present in the environment which is whyechoprints 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 $abcprintsenv varstill 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:08SHELLis managed directly by the shell. The shell manages many such variables. For a full list of shell such variables set by bash, look inman bashfor the section entitled "Shell Variables". – John1024 Aug 13 '15 at 07:09