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
scott
[0054][scott@linux:~]$ echo $HOME
/home/scott
[0055][scott@linux:~]$

   

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 TLDP.org Advanced Bash-Scripting Guide.

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

OpenSUSE Linux Rants
Official OpenSUSE Linux Site

internal links:

categories:

SUSE Resources

search blog:

archives:

December 2006
S M T W T F S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

59 queries. 0.810 seconds