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

Enable/Disable Your Network Interface

Today we'll cover one way to enable or disable your network interface in the Linux…

5 months ago

Check Your NIC Speed In The Terminal

Today's exercise is a nice and simple exercise where we check your NIC speed in…

5 months ago

Easily Monitor Your Wireless Connection

Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…

6 months ago

Count The Files In A Directory

I think I've covered this before with the ls command but this time we'll count…

6 months ago

Get System Information With The ‘uname’ Command In Linux

Today we'll be learning about a basic Linux command that's known as 'uname' and it…

6 months ago

hardinfo Has Been Rebooted As hardinfo2

If you've used hardinfo in the past, it may interest you to know that hardinfo…

6 months ago