You should undertstand the difference between the environment variables belonging to a process (they are not in a file, but belong to a process and that is something that is in memory) and the several files that contain (mostly bash) statements to set/unset these variables.
You should also understand the difference between variables being set and available for use inside a shell (bash) process (a running bash script) and those that are in the process environmnet and also available through the same means in such a shell process.
Sounds difficult and it is, as long as one does not understand (as with so many things ; ).
First, what is a process? It is an instance of an executable being executed. That is it occupies some space in memory and has a program counter that points to the place where the execution is. The place in memory is ocupied by several things. Amongst them the code to be executed and the data used. But also a part in memory contains a list of variables and their values. These are called the environment. A process is allways started from within another process (the parent) and to begin with it inherits the environment of the parent. At start the kernel also contributes some values (amongst other things, the name the program is called with, and the parameters added to the call). These environment parameters can be changed from with the child process. And when it calls another (granchild) process, these changed values are given to it.
Now the shell script (we tak bash here). A process can be a running shells cript. A shell script is written in a programming language that is not compiled, but interpreted, that is, the statements are read and executed from the script file. In every programing language you can use variable to store data. In bash you do this by typing things like:
MYAGE=16
You can then use that variable in other statements like
echo $MYAGE
Now bash has the feature that it also makes available the environment variables of the running process (the script) in the same way. Thus you can do
echo $PWD
to see your current workind directory.
So it is easy to get the environment variable from the environment and also easy to change them:
henk@boven:~> echo $PWD
/home/henk
henk@boven:~> PWD=/home/henk/Documents
henk@boven:~/Documents>
As you see I changed de variable with the immediate effect the same as if I had done
cd Documents
Some environment variables are read-only (else you could do very strange things).
But how can you add a new one to the envirionemnt?
Simply saying
MYAGE=16
does not work, MYAGE is then only available with value 16 in the running script.
But
export MYAGE=16
does place MYAGE in the envirionment. Once it is there and you want to change the value there is no need to use export again.
I hope you now understand what all sorts of asignments in startup sequences as .profile, .bashrc and the like do. They either change variables in the environment (when they are allready there) or create new ones (with *export, *but using export does not mean it wasn’t there before).
And never forget that those environment variables are inherited by offspring processes (never backwards up to he parents of course).
Thus when you say:
export DISPLAY=othersystem.other.domain:0
xclock
You will start the X program xclock not on your own display, but on the display of system othersystem.other.domain (when the security settings of the network and the other system allow). Beacuse when the xclock process starts, it will see in it’s herited environment where it has to open it’s window.