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.
envThis 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 HOMESince 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 PATHThis 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
EasyUse 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:
envThe printenv command works similarly. Without arguments, it shows all variables:
printenvTo display a specific variable with printenv, pass the variable name without the $ prefix:
printenv HOMEYou can filter the output using grep:
env | grep PATHTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline12Environment
Environment VariablesView All VariablesThe PATH VariableSetting A VariableExport A VariableThe Profile FileRecap - Custom Environment