To list your environment variables in Linux, you can use a few different commands depending on how much detail you need.
Here are the most common ways:
1. Using the env command
The simplest way to see all environment variables inherited by the current shell is to type:
env
This will print a long list of KEY=VALUE pairs for every environment variable currently set.
2. Using the printenv command
This is very similar to env and is widely used:
printenv
Pro Tip: If you only want to see the value of a specific variable (without the $ sign), you can pass the name to printenv:
printenv PATH
3. Using export
If you run export without any arguments, it lists all variables that have been exported to the environment, usually formatted in a way that shows how they were defined:
export
4. Searching for a specific variable
Since the list can be quite long, it is very common to "pipe" the output into grep to find exactly what you are looking for:
env | grep MY_ENV_VAR
In your current lab activity, try running env in your terminal to see the list, and then try env | grep MY_ENV_VAR to find the specific one you created in Step 3!