Frequently Asked Question
What is the difference between an environment variable and a shell variable?
A shell variable exists only in the current shell. When you write NAME="Alice",
NAME is set, the shell can see it, and echo $NAME prints Alice. But any program
you launch from that shell, even another bash, will not see it. Shell variables
are useful for short-lived state inside scripts and interactive sessions.
An environment variable is one the shell has marked for export to its children.
You promote a shell variable with export NAME (or set and export in one go with
export NAME="Alice"). When the shell forks a new process, the kernel copies the
list of exported variables into the new process's environment, so the program sees
NAME=Alice in environ. PATH, HOME, USER, LANG, and EDITOR are all
ordinary environment variables, there's nothing special about them except that
countless programs read them. env lists every exported variable in the current
process; set lists every shell variable (which is a superset).