|
What is an environment variable?Environment variables set defaults for your shell to use to make life easier. They store data like which directory to look in for your home directory, which text editor you prefer, or which directories to check when running programs. If you didn't have your path environment variable set, you would have to run /usr/local/bin/programname or /usr/sbin/programname or whichever directory the program is in followed by its name, rather than simply typing in the name of the program you want to run.You can find out what your environment variables are in csh/tcsh by running setenv. In bash you should run export. To find out what a specific variable is set to, you can run echo $VARIABLENAME, which should work in any shell.
Some examples of environment variables
There are other environment variables besides those listed. The quickest way to find out about them is either to ask someone who knows or search the web.
Why do I want to change it?If you find yourself typing /usr/sbin/nslookup all the time or you know there's only one copy of a program installed but for some reason you have to specify the full path, you might want to change your PATH variable. If you try to run a program and it complains that it can't find the necessary library or java class, you might want to change LD_LIBRARY_PATH or CLASSPATH. When your account was created default values were provided for all these variables, but at some point you might need different ones. And besides, it's a lot easier than typing full paths all the time or editing the source of programs to find the right library.
How to change evironment variables:
in csh/tcsh:If you want to temporarily set an environmental variables (that is, it will only apply to the current session, and when you log out and log in it will default back to whatever you previously had), you should run from the command line setenv VARIABLENAME "value" For example, if you want to set your path to first look in /bin, then /usr/bin, then /usr/sbin, then /usr/scb/bin, you would type: setenv PATH "/bin:/usr/bin:/usr/sbin:/usr/ucb/bin" If you want to set a variable for every time you login, you should add the setenv line to your .cshrc file in your home directory. If the variable is already set in that file, you may want to change the current line instead of adding another. Run source .cshrc to make the changes apply to the current session. in bash:To temporarily set environmental variables for the current session, you should run export VARIABLENAME="value" For example, to set your path as mentioned above, you would type: export PATH="/bin:/usr/bin:/usr/sbin:/usr/ucb/bin" As in csh/tcsh, to set the variable for all sessions, you should add it to the .bashrc file in your home directory, then run source .bashrc to apply the changes. in other shells:Most shells accept either setenv or export. For specifics on your shell, check your shell's man page.
HMC Computer Science Department
Contact Information
Last Modified Monday, 23-Jul-2001 14:11:25 PDT
|