When you type a command, HP-UX must be able to find
the directory containing the command before it can run the command.
The PATH environment variable contains a list of directories
you want HP-UX to search when looking for commands. Your PATH
should contain all the directories necessary to locate all the commands
that you use.
PATH Variable Format |
 |
The PATH variable is read from your .profile or
/etc/profile login script. It contains a list of directories to
search, separated by colons. There should be no spaces surrounding
the colons. You can also use the echo command to determine the
current value of PATH, as follows:
echo $PATH
/usr/bin/sh:/usr/bin:/usr/local/bin
|
This line means that when you type a command, the shell first searches for
the command in the /usr/bin/sh directory, in the /usr/bin
directory, and then in the /usr/local/bin directory.
If the command is not found in any of these directories, the shell
displays this message:
command_name: Command not found.
|
Changing PATH |
 |
If the shell can't find a command that you know exists,
you have two options:
Type the full path name of the command. For example, if you wish to execute a command called prog, and it resides in the directory /home/leslie/bin, type this:
Or, change the value of the PATH variable to add the command path, a better long-term solution if you use the command frequently.
The following table shows the path names of the most frequently use directories.
- Directory
What It Contains
- /usr/bin
Frequently used HP-UX commands.
- /usr/sbin
Commands the system administrator uses.
- /usr/bin/sh
POSIX Shell
- /usr/contrib/bin
Contributed programs not supported by Hewlett-Packard.
- /usr/local/bin
Programs and commands written at your location.
- $HOME/bin
A directory you might create for your own shell
scripts and programs.
 |
 |  |
 |
 | CAUTION: Because of the potential security risk, do not
put your current directory (usually represented as .) as
the first element in PATH. Leave the current directory out of your
PATH, or include it only as the last element.
|
 |
 |  |
 |
Remember that directories in PATH are searched in the order
in which they appear (left to right). In general,
put the most frequently used directories first in the path--unless
two commands in the search path
have the same name (for example, /usr/bin/rm and $HOME/bin/rm).
In this example, if you want the shell to find your version of rm
first, put $HOME/bin before /usr/bin in PATH.
The following example shows how to alter PATH to include $HOME/bin
before any other directories, and to include the current directory as
the last directory in the search path (this example assumes you're
using the POSIX, Bourne, or Key Shell):
echo $PATH
/usr/bin/sh:/usr/bin:/usr/bin:
/usr/contrib/bin:/usr/local/bin
PATH=$HOME/bin:$PATH:.
Including . as the last element makes the current directory the last one searched.
echo $PATH
/home/terry/bin:/usr/bin/sh:/usr/bin:
/usr/bin:/usr/contrib/bin:/usr/local/bin:.
|
Setting PATH as an Environment Variable |
 |
Normally, you set PATH as a environment variable, so it is set to
the appropriate value when you log in. In the Bourne and POSIX Shells,
you can change PATH in the .profile script and export it. You
can find out more about these scripts in Shells: User's Guide.