Linuxlab

Environment variables in Linux: env and export

Updated July 3, 2026

An environment variable is a name-value pair that a process passes down to its children.

Common cases

env                  # all environment variables
echo "$HOME"          # the value of one variable
export EDITOR=vim    # create and export
NAME=value command  # set a variable for one command only

How it works: export and inheritance

A plain variable x=5 lives only in the current shell. export x marks it as an environment variable, and then every process started from that shell (its children) receives it. Inheritance goes one way, down: a child cannot change its parent's environment. That is why settings like EDITOR or PATH are exported, so the programs you launch can see them.

Used in

You need this in the lesson The shell environment. The theory is the chapter The shell environment and configuration.

See also

The PATH variable, The ~/.bashrc file.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.