The shell maintains several environment variables which are used to store information used by the shell. The PATH environment variable lists the directories in the order that the shell will search when trying to locate an executable file. You can display the environment variables with the set command (the env and printenv commands do the same thing),
$ set
a lot of stuff scrolls by
$ set | less
In the second set command, the output is being piped through the less program. To change the value of an environment variable, use varname=value,
The following example changes MYNAME variable as well as the PATH variable. The PATH variable designates where BASH looks when it runs commands. For instance, the /bin directory is in the PATH variable, so when commands are run, it will look in that directory for the command. If you are creating executables and would like bash to look in the current directory for commands you type, you can add '.' to the PATH (remember '.' represents the current directory).
$ MYNAME=Kevin
$ set | grep MYNAME
MYNAME=Kevin
To add . and sbin to your path,
$ PATH=/sbin:$PATH:.
$ set | grep PATH
PATH='/sbin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:.'
Setting an environment variable at the Bash command prompt only changes the value of the environment variable for this session. To make the change permanent (so the variable will be defined when you log in again), edit your .bashrc file in your home directory, and add the lines,
MYNAME=Kevin; export MYNAME
PATH=/sbin:$PATH:.; export PATH
The special file .bashrc contains commands that are executed whenever a "new environment" is created, i.e., whenever a new shell is started. The next time you log in the environment variables will be updated. To delete an environment variable, use the unset command, e.g., unset MYNAME.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment