I've been using Environment variables for ages but only just read about Environment variables vs. Shell variables. According to the definition:
- Environment variables are "system-wide" and inherited by child shells and processes
- Shell variables are only valid in the shell in which they are set
The book I'm reading goes on to state that using export takes a variable in your current environment (bash shell) and makes it available in any every environment until you change it again.
But if I change an Environment variable (HISTSIZE, for example) by calling export HISTZISE=999
, and then check the value in a different terminal tab (echo $HISTSIZE
), the change isn't visible. Why is this if the change is supposed to be system-wide? Personally I'm used to always setting my Environment variables when opening a new terminal tab, and I had taken it for granted that exporting values wouldn't affect other tabs (shells?).
So my question is: Are different terminal tabs considered different shell environments? And what does "system-wide" then mean?
Thanks for the help!
Best Answer
export
exports a variable to all children of the current shell.So if you do
you'll see the value of $somevariable in this new shell.
However shells in other terminal tabs are not children of the shell in the first tab, so they won't inherit the exported variables.
The shells in terminal tabs are all children of the gnome process that opened the terminal, so they are "brothers and sisters". You can verify this by calling
ps -f
in two terminal tabs and looking at the column PPID (parent process ID) of the bash line. In my example both have the parent 5319 which is the gnome terminal process.tab 1:
tab 2: