export creates a global environment variable?
So, until now I knew that export is creating a global environment variable that can be accessed by any process. But I tried the following and it didn't work.
I opened a terminal and typed Code:
export a=1 Then, I opened a new terminal and typed Code:
echo $a Why is that? In my ~./bashrc script (provided by my Linux distribution Arch Linux) I have the following exports: Code:
#Environment Variables Why this works in the bashrc script and not in the way I described at the top of this post? Thank you. |
~./bashrc is used every time you open bash terminal.
Put export a=1 in ~./bashrc In one terminal enter Code:
export PATH=fred Code:
echo $PATH |
Quote:
Code:
export a=1 Code:
a=1 Code:
LIBGL_ALWAYS_SOFTWARE=1 Code:
export LIBGL_ALWAYS_SOFTWARE=1 |
Quote:
There is, however, something called a login shell, which parses various startup files (e.g. ~/.bash_profile if you're using bash). It's some kind of Uber-shell. I'm sure somebody will be along shortly and give you the technical details. Or you could perform a web search. |
Quote:
BTW: you can export a variable even before setting (or changing) it, but afterwards too. So both Code:
export a Code:
a=1 Once exported, the variable stays in the enviroment. |
Quote:
Does that make sense? It'd sure be nice if I could make a change that I'd like to be "global" after I've already opened terminals and applications in ten different activity windows without havng to log out and back in again but UNIX/Linux doesn't work that way. All you can do is plan ahead: make the change in whatever defines your environment at login and it'll be there when you login the next time in all the terminals you open up. HTH... |
Everything makes sense now guys. One last thing. The first program that starts inside a terminal, for example:
Code:
export myvar = 5 |
Quote:
A shell script can be run either by a new (child) instance of the shell (or a different one, if you used #!/bin/<someshell> as its first line) OR by the current shell itself. In that case the alternate shell line is ignored, and you have to start it as Code:
. script or |
Quote:
A workaround is to make such a change in "whatever defines your environment at login" (e.g. ~/.bashrc) in one terminal and then source it: Code:
. ~/.bashrc |
Quote:
|
All times are GMT -5. The time now is 10:25 AM. |