Environment (Variables)

Environment

  • Process attribute

  • Inherited from parent to child process during creation

  • An array of C strings of the form var=value

../../../../../../_images/environment.svg

Shell: Environment Variables, And Process Creation

In the shell, for example, you can see the value of the PATH environment variable like …

$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin

You set the value of an environment variable

Prepend home to $PATH, and create new variable MY_VARIABLE
$ PATH=$HOME/bin:$PATH
$ MY_VARIABLE=hello

In case the variable is not exported, you export it [1],

$ export PATH
$ export MY_VARIABLE

Now the parent process (PID 1034184) has an environment variable PATH with value /home/jfasch/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:

$ echo $$
1034184
$ echo $PATH
/home/jfasch/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin

In that shell, start a new shell. This looks like nothing happened (the prompt is the same at least), but it has a new PID:

$ bash
$ echo $$
1035812
../../../../../../_images/environment2.svg