Environment (Variables)¶
Environment¶
Process attribute
Inherited from parent to child process during creation
An array of C strings of the form
var=value
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
$ 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
Popular Environment Variables: HOME
, SHELL
, USER
¶
Set at login time (for example by
sshd
)User’s metadata, found in
/etc/passwd
Made available to all processes in the login session
⟶ simply by setting them early in the session’s ancestor process
$ echo $HOME
/home/jfasch
$ echo $SHELL
/bin/bash
$ echo $USER
jfasch
Popular Environment Variables: PATH
¶
Set during shell startup
From various configuration files that extend
PATH
incrementally/etc/profile
: system wide~/.bashrc
: per user
Footnotes