Every process has an environment: a list of variables with values. When a process starts a child process, the child gets a copy of the parent's environment.
Variables in the environment are environment variables. The variables that you set with NAME=value are only shell variables. They stay in your shell, and children do not get them.
Some environment variables
Your shell had these from the start:
| Variable | Holds | Example |
|---|---|---|
HOME | The path of your home directory | /home/learner |
USER | Your username | learner |
SHELL | The program of your login shell | /bin/bash |
PWD | The current directory | /home/learner/shop |
PATH | Where the shell looks for programs | A lesson of its own |
~ is a short form of $HOME.
printenv: list the environment
learner@tidepool:~$ printenv HOME
/home/learner
learner@tidepool:~$ printenv
HOME=/home/learner
USER=learner
SHELL=/bin/bash
...printenv lists only environment variables. A shell variable is not in the list.
See it with a child process
bash -c 'LINE' starts a new bash process, a child of your shell, that runs LINE. Use it to see what a child gets:
learner@tidepool:~$ COLOR=green
learner@tidepool:~$ echo $COLOR
green
learner@tidepool:~$ bash -c 'echo $COLOR'
learner@tidepool:~$ bash -c 'echo $HOME'
/home/learnerThe child got HOME, an environment variable. It did not get COLOR, a shell variable. The single quotes make sure that the child, not your shell, reads $COLOR.