Menu
Coddy logo textTech

View All Variables

Part of the Fundamentals section of Coddy's Terminal journey — lesson 60 of 82.

Sometimes you need to see all the environment variables at once, not just one at a time. The env command displays every environment variable currently set in your shell session.

env

This outputs a list of variable names and their values, each on its own line in the format NAME=value. You'll see familiar ones like HOME and USER, along with many others the system sets automatically.

The printenv command works similarly. Without arguments, it shows all variables just like env. You can also use it to display a specific variable without the $ prefix:

# Show all variables
printenv

# Show a specific variable
printenv HOME

Since the output can be quite long, you might want to combine these commands with tools you've already learned. For example, piping to grep helps you find specific variables:

env | grep PATH

This filters the output to show only lines containing "PATH", making it easier to find what you're looking for in the sea of environment variables.

challenge icon

Challenge

Easy

Use printenv to display the value of the USER environment variable.

Unlike echo, the printenv command lets you view a specific variable without using the $ prefix. Simply pass the variable name as an argument.

Your output should display your current username.

Hint: The command format is printenv VARIABLE_NAME

Cheat sheet

To display all environment variables, use the env command:

env

The printenv command works similarly. Without arguments, it shows all variables:

printenv

To display a specific variable with printenv, pass the variable name without the $ prefix:

printenv HOME

You can filter the output using grep:

env | grep PATH

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals