Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: where are environment variables stored?

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.

like image 227
Ben L Avatar asked Feb 10 '09 12:02

Ben L


People also ask

Where is environment variables stored in Linux?

In Linux and Unix based systems environment variables are a set of dynamic named values, stored within the system that are used by applications launched in shells or subshells.

Where are environmental variable stored?

Machine environment variables are stored or retrieved from the following registry location: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment . Process environment variables are generated dynamically every time a user logs in to the device and are restricted to a single process.

Where are bash environment variables stored?

You can set your own persistent environment variables in your shell configuration file, the most common of which is ~/. bashrc. If you're a system administrator managing several users, you can also set environment variables in a script placed in the /etc/profile.

Where is environment variables in Ubuntu?

On Ubuntu, there are two system-wide environment variables, both files need admin or sudo to modify it. /etc/environment – It is not a script file, purely assignment expressions, one per line. /etc/profile. d/*.


1 Answers

The environment variables of a process exist at runtime, and are not stored in some file or so. They are stored in the process's own memory (that's where they are found to pass on to children). But there is a virtual file in

/proc/pid/environ

This file shows all the environment variables that were passed when calling the process (unless the process overwrote that part of its memory — most programs don't). The kernel makes them visible through 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.

like image 174
Johannes Schaub - litb Avatar answered Oct 04 '22 13:10

Johannes Schaub - litb