How To: Show All Environment Variables

Today’s article is going to show you how to show all your environment variables in Linux. There are quite a few and some of them can be quite useful. If you don’t know what an environment variable is, we’ll cover that briefly as well.

So, what is an environment variable? It’s a static name for a dynamic value. In other words the system has information that varies, but using an environment variable will point to the dynamic information as though it was static.

As an example, we can use ‘echo $PWD‘ in the terminal and it will output the present working directory. If you change the directory and run that command again, it will output the new present working directory. You can do things like ‘echo $SHELL’ and it will tell you the shell you’re using, even if you’ve changed from the default shell. Things like that are the point of having environment variables.

These things really shine when used for things like scripting. They’re useful when you’re not certain of the architecture they’ll be used on and still want the script to work predictably wherever it is used. You’ll also see environment variables put to work in programming. They’re pretty handy, as I said!

If you’d like to see an example, read my article about clearing EXIF data for privacy’s sake. Scroll down to find the alias example I included and you’ll see the $PWD environment variable at work. See? It’s pretty easy and effective. So, let’s see a few ways to show all environment variables.

Show All Environment Variables:

Like most articles, you’re gonna need an open terminal. You can do that with your keyboard, by pressing CTRL + ALT + T and your default terminal should open.

Now that you have your terminal open, we’ll start with the first way to show all the environment variables:

env

You can also use:

printenv

You can also use the following command, but I don’t recommend doing so. It’s here for the sake of completeness and the command will output a lot of gibberish that’s really of no value to the average user.

set

Now that you know how to show them, here are a few handy examples that further demonstrate what an environment variable does.

Show home with:

echo $HOME

Find the system language with:

echo $LANGUAGE

Or find the desktop environment in use with:

echo $XDG_CURRENT_DESKTOP

Those are just a few of the environment variables available to you as a Linux user. If you make use of these on a regular basis, please leave a comment explaining how you use them.

Closure:

Yup… Another article. Another step closer to the anniversary of this site. I still have some content to move over from the original site, but writing completely new stuff is pretty fun. Seriously, it’s pretty fun. Please feel encouraged to write an article or two, considering I normally take the whole month of January off!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

 

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Short: The Halt Command

Today's article is intentionally short because we're simply going to learn about the basics of…

1 day ago

Installing Flatpaks In Linux

Today we're going to have a pretty easy article where you'll learn about installing Flatpaks…

3 days ago

A Quick Look At The Shutdown Command

This is going to be just a quick article about a command many of you…

5 days ago

Setting Up Coding Environments on Linux for Educational Use

With so many strong attributes, such as robustness and flexibility, Linux stands as a powerful…

1 week ago

View Detailed Hardware Information

There are many tools for showing your hardware information and today we'll get to view…

1 week ago

How To: Install Wine In Lubuntu

Today's article isn't going to be complicated or long as we are going to cover…

2 weeks ago