OpenSUSE Linux Rants

OpenSUSE Linux Tips, tricks, how-tos, opinions, and news

My Resume  -  My LinkedIn Profile

December 1, 2006

Accessing Environmental Variables in Linux

by @ 7:57 am. Filed under bash, SUSE Tips & Tricks

I have just enough time to post a quick note about yet another cool thing Linux has to offer. When you are working from the command-line, there are some environmental variables that can be very useful to know about when writing bash scripts. For example, if you wanted to know the username of the user currently logged in, you might access the $USER environmental variable. If you wanted to determine this user’s home directory, you would use $HOME. In reality, there are a whole bunch of environmental variables that you may find useful for bash scripts and whatnot.

To take a look at these variables and what they are set to, try this out:

[0054][scott@linux:~]$ echo $USER
[0054][scott@linux:~]$ echo $HOME


To examine environmental variables further, take a look at the env command. Pop open a terminal window and run that. It displays about two screens full of environmental variables. If you are ever in need of knowing what these variables are set to, whip out your trusty env tool and see what it says.

For bash scripting, another great resource for variables accessible from within scripts is here in the Advanced Bash-Scripting Guide.

Oh, and check out the new poll I have posted (right side of the page => ).

3 Responses to “Accessing Environmental Variables in Linux”

  1. GN Says:

    i knew this 😉

  2. Scott Morris Says:

    Right on, man! I wrote it as a reminder note for myself. 🙂

  3. Viktor Says:

    The Bash Scripting guide will definetly come in very handy Scott!

    Glad to see your posting a little more often 🙂

OpenSUSE Linux Rants
Official OpenSUSE Linux Site

internal links:


SUSE Resources

search blog:


February 2018
« Mar    

55 queries. 1.072 seconds