Environment Variables
Part of the Fundamentals section of Coddy's Terminal journey — lesson 59 of 82.
Environment variables are named values stored in your shell's memory that programs and commands can access. Think of them as settings that shape how your terminal session behaves.
Every time you open a terminal, the system automatically sets up several environment variables. These store useful information like your username, home directory path, and preferred text editor. Programs read these variables to understand the context they're running in.
To view the value of a specific environment variable, use the echo command with a $ prefix before the variable name:
echo $HOMEThis displays your home directory path. The $ tells the shell to substitute the variable's value. Here are a few common environment variables:
| Variable | Contains |
|---|---|
| HOME | Your home directory path |
| USER | Your username |
| SHELL | Your current shell program |
| PWD | Present working directory |
Without the $, echo would just print the literal text "HOME" instead of the variable's value. This distinction between the variable name and its value is important to remember as you work with environment variables.
Challenge
EasyUse the echo command to display the value of the SHELL environment variable.
Remember to use the $ prefix before the variable name to access its value. Without the $, you would just print the literal text "SHELL" instead of the actual shell path.
Your output should display the path to your current shell program (something like /bin/bash).
Hint: The command format is
echo $VARIABLE_NAME
Cheat sheet
Environment variables are named values stored in your shell's memory that programs and commands can access.
To view the value of an environment variable, use echo with a $ prefix:
echo $HOMEThe $ tells the shell to substitute the variable's value. Without it, echo prints the literal text instead.
Common environment variables:
| Variable | Contains |
|---|---|
| HOME | Your home directory path |
| USER | Your username |
| SHELL | Your current shell program |
| PWD | Present working directory |
Try 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