[ Team LiB ] Previous Section Next Section

Recognizing Problems with Search Paths

If a user types a command that is not in the search path, the message Command not found is displayed. The command might not be found because the command is not available on the system or the command directory is not in the search path.

If the wrong version of the command is found, a directory with a command of the same name is in the search path. In this case, the proper directory may be found later in the search path or may not be present at all.

To diagnose and troubleshoot problems with search paths, use the following procedure.

  1. Display the current search path.

  2. graphics/new.gif Edit the file in which the user's path is set (.login for the C shell, .profile for the Bourne and Korn shells). Add the directory or rearrange the order of the path.

    graphics/new.gif

    NOTE. For the C shell, always check both the .cshrc and .login files to make sure the path information is set all in one place. When you find path information in the .cshrc file, move it to the .login file. Duplicate entries can make the search path harder to troubleshoot and make search times less efficient for the user.


  3. Source the file to activate the changes. See "Sourcing Bourne and Korn Shell Dot Files" and "Sourcing C Shell Dot Files" on page 437 for more information.

  4. Verify that the command is found in the right place.

  5. Execute the command.

The tasks you use to follow this procedure are described in the following sections.

Displaying the Current Search Path

To display the current search path, type echo $PATH and press Return. The current search path is displayed.


cinderella% echo $PATH
/sbin:/usr/sbin:/usr/bin:/etc
cinderella%



Setting the Path for Bourne and Korn Shells

The path for the Bourne and Korn shells is specified in the user's $HOME/.profile file in this way.


PATH=/usr/bin:/$HOME/bin:.;export PATH

The dot (.) at the end of the path specifies that the current working directory is always searched last.

Sourcing Bourne and Korn Shell Dot Files

When you have changed information in the .profile file, you must source the file to make the new information available to the shell. To source the .profile file, type . .profile and press Return.


$ . .profile
$



Setting the Path for the C Shell

graphics/new.gif

Specify the path for the C shell in the user's $HOME/.login file (with the setenv PATH environment variable) in this way.


setenv PATH (/usr/bin $home/bin .)

The dot (.) at the end of the path specifies that the current working directory is always searched last.

Sourcing C Shell Dot Files

When you have changed information in the .login file, you must source the file to make the new information available to the shell. To source the .login file, type source .login and press Return.


castle% source .login
castle%



Verifying the Search Path

graphics/new.gif

When you have changed a user's path, use the which command to verify that the shell is finding the proper command. The which command looks in the .cshrc file for information. The /bin/which command is a C shell script. Any configuration files in a user's home directory that affect the C shell also may affect the which command. To ensure accurate results, use the which command in a C or tcsh shell. Alternatively, from the Korn or zsh shell you can use the whence command instead of the which command.

To verify the search path, type which command-name and press Return. If the command is found in the path, the path and the name of the command are displayed.

The following example shows that the OpenWindows executable is not in any of the directories in the search path.


oak% which openwin
no openwin in . /home/ignatz /sbin /usr/sbin /usr/bin /etc/home/ignatz/bin
  /bin /home/bin /usr/etc
oak%

The following example shows that the executable for OpenWindows is found among the directories in the search path.


oak% which openwin
/usr/openwin/bin/openwin
oak%

If you cannot find a command, you can often look at the manual page to find its path name. For example, if you cannot find the lpsched command (the LP printer daemon), the lpsched(1M) manual page tells you the path is /usr/lib/lp/lpsched.

Executing a Command

To execute a command, type command-name and press Return. The command is executed if it is in the search path. You can always execute a command that is not in the search path by typing the full path name for the command.

    [ Team LiB ] Previous Section Next Section