Exploring Environment and Shell Variables

Learn the basics of the environment and shell variables.

We'll cover the following

The two types of variables are environment variables and shell variables. Environment variables are defined in the current shell session and are available to any programs executed. Environment variables often control how programs work. For example, we might set a LANG environment variable that other programs can use to determine the language a program should use to communicate with us. Shell variables are similar, except they’re not available to programs and subprocesses. We can think of environment variables as global variables and shell variables as local ones.

Environment variables

The env command shows us all the environment variables that are set. There’s a lot, so we pipe the results to less:

$ env | less

Use the terminal below to practice these commands.

Get hands-on with 1200+ tech skills courses.