views:

5666

answers:

6

If I type into a terminal,

export DISPLAY=:0.0

... where is the shell storing that environment variable?

I'm using Ubuntu 8.10. I've looked in the files ~/.profile and /etc/profile and can find no trace of DISPLAY.

+5  A: 

Type "set" and you will get a list of all the current variables. If you want something to persist put it in ~/.bashrc or ~/.bash_profile (if you're using bash)

MrWiggles
A: 

That variable isn't stored in some script. It's simply set by the X server scripts. You can check the environment variables currently set using set.

Eduard - Gabriel Munteanu
Actually, it's set *by* the shell *for* the X clients.
paxdiablo
Of course, it's set by the scripts that bring the X server up.
Eduard - Gabriel Munteanu
+4  A: 

It's stored in the process (shell) and since you've exported it, any processes that process spawns.

Doing the above doesn't store it anywhere in the filesystem like /etc/profile. You have to put it there explicitly for that to happen.

cletus
+16  A: 

The kernel stores the list of environment variables and their values for each process, and inherit them to child processes. They exist at runtime, and are not stored in some file or so. But there is a virtual file in

/proc/<pid>/environ

Which contains all the environment variables. The kernel makes them visible by that virtual file. One can list them. For example to view the variables of process 3940, one can do

cat /proc/3940/environ | tr '\0' '\n'

Each variable is delimited by a binary zero from the next one. tr replaces the zero into a newline.

Johannes Schaub - litb
Is this information Linux specific?
cletus
cletus, yes i think it is linux specific, but i don't know.
Johannes Schaub - litb
Anything in `/proc` should be presumed to be OS specific. Writing programs that look at `/proc` is a big WTF for me.
asveikau
@askveikau, note that I do not propose to use that file by a program to read environment variables. I showed that the linux kernel exports them into that file - no more and no less. That said, I don't know what guarantees the linux kernel makes with regard to that file.
Johannes Schaub - litb
A: 

There is a very good explanation of all that at https://help.ubuntu.com/community/EnvironmentVariables

Guillaume
A: 

here is a simple tutorial on the subject I thought I should share with you guys http://www.geeksww.com/tutorials/operating_systems/linux/tips_and_tricks/working_bash_environment_variables_beginners_linux.php

shahryar
This doesn't relate to the question at all.
Ignacio Vazquez-Abrams