-->
Previous | Table of Contents | Next |
The PATH variable contains a colon-delimited string that points to all the directories containing the programs you use. The order in which these directories are listed determines which directories are searched first. The list order is important on systems that support several different forms of the same command. Your system may also have locally created commands you may want to access. For example, your PATH variable may contain the following values:
/usr/ucb:/bin:/usr/bin:/usr/local/bin
This statement tells your shell to explore the /usr/ucb directory first. If the shell finds the command in the first directory it searches, it stops searching and executes that command. The /bin and /usr/bin directories contain all the standard Linux commands. The /usr/local/bin directory often contains the local commands added by you and other users of your system. This task of adding local commands is usually the responsibility of the system administrator.
If you are acting as the system administrator, or if you want access to the more system-oriented commands, you will probably want to add /usr/sbin or /usr/local/sbin or both to shorten the effort of typing /usr/sbin/traceroute.
If you intend to create your own commands, you can modify the PATH variable to include directories that contain your own commands. How you do this depends on which shell you use. For example, if you use the Bourne or Korn shell, you can add a directory to your PATH variable by typing the following at the command prompt:
$ PATH=$PATH:newpath
When you place a $ in front of the name of a variable, its current value is substituted. In this command, the $PATH variable represents whatever the current path is; the colon and the newpath parameters add to the current path.
The following section describes several other ways of manipulating variables in your environment. For now, its sufficient to say that the shell environment contains variables and functions and that these objects can be manipulated by both shells and application programs. Application programs can access and modify the environment, but they generally manipulate variables within the program. Shells, on the other hand, can only manipulate variables in the environment.
Using Special Shell Variables
The shell keeps track of a number of special variables. You can see what they are with the env command, which lists the variables available to you within your working environment. Following is an abbreviated list of what you might see when you enter env:
HOME=/usr/wrev SHELL=/bin/sh MAIL=/usr/mail/wrev LOGNAME=wrev PATH=/bin:/usr/bin:. TZ=PST8PDT PS1=$ TERM=vt100
Any of these special variables can be used in the same way you use any other shell variable. Table 18.3 defines the special variables.
Variable Name | Meaning |
---|---|
HOME | Full path name of your home directory |
SHELL | Name of your current shell |
Full path name of your mailbox | |
LOGNAME | Your login name |
PATH | Directories the shell searches for commands |
TZ | Time zone for the date command |
SECONDS | Number of seconds since invoking shell |
PS1 | System prompt |
TERM | The type of terminal youre using |
The HOME Variable
The HOME variable always specifies your home directory. When you log in, youre in your home directory. Occasionally, you use the cd command to move to other directories. To change to the directory /usr/local/games, for example, enter cd/usr/local/games. To get back to your home directory, all you have to do is enter cd. You can use the HOME variable when youre writing shell scripts that specify files in your home directory. Rather than write a command such as grep $number /usr/wrev/sales/data.01, its better to enter the command as grep $number $HOME/sales/data.01 for these reasons:
Previous | Table of Contents | Next |