Carnegie Mellon University Website Home Page
 

Search Paths: Using Search Paths on Andrew

What is a Search Path?

A search path is the list of directories in which the UNIX shell looks to find programs that you want to use. When you issue a command, the UNIX shell looks in each directory listed in your search path in sequence and runs the first program that matches the command you gave. A global search path is set for you automatically when you login and you can add directories to it if you wish.

Global Search Path

The global search path is the search path which Andrew System administrators provide for all Andrew users. In general, it includes these directories:

on Andrew Linux:

/usr/local/bin
/usr/edubin
/bin
/usr/bin
/usr/contributed/bin

on Andrew Solaris:

/usr/local/bin
/usr/ccs/bin
/opt/SUNWspro/bin
/usr/java/bin
/usr/edu/bin
/usr/ucb
/bin
/usr/contributed/bin
/usr/openwin/bin 

A bin directory is where binary, or complied, versions of programs are conventionally stored. Your own bin directory is always included in the global search path, so you never need to add it to your personal search path. The global search path is maintained in the file /usr/local/lib/global.path , which is referenced, or sourced, by the file /usr/local/lib/global . login .

Each time you log into Andrew, the commands in the .login file are sourced. If you examine the copy of .login in your home directory, you will see that the first line in the file is:

source /usr/local/lib/global.login

his source line, which includes standard configuration information, ensures that all currently supported system directories are available. Changes to your .login file should be made after this line.

Adding Directories to the Search Path

To add a directory to your search path:

  1. Open your .login file for editing.
  2. After the line, source /usr/local/lib/global.login , add the new search path. Search path lines are of the form:

    set path=($path <path>)

    Note:
    In the set path line above, $path refers to the path already set by the global.login file. This line tells the computer, "Set my path to be: the path set by the global .login file $path plus <path>, in that order."
  3. Save your changes.

Example

To add a directory called ~hb0v/bin to your search path, you would need to add the line:

set path=($path ~hb0v/bin)
to your .login file somewhere after the line:
source /usr/local/lib/global.login

ontrolling the Order of the Search Path

The order in which the search paths appear in your .login determines the order in which the directories are searched. The normal method for setting the search path searches the system directories first and then searches the path you specify because it is the last directory in your search path line. However, there may be times when you want to search a specific directory before searching the system directories. To set your path to search a specific directory before the system directories:

  1. Use a search path of the form:

    Set path= (<path> $path)

    Note:
    In the set path line above, $path refers to the path already set by the global.login file. This line tells the computer, "Set my path to be: <path> plus the path set by the global .login file, in that order."

Example

One of your professors may want your class to use a modified version of a program that is already installed on one of the default paths. In this situation, you will need the UNIX shell to find the class's version of the program before the system version. If your class directory is 15-211 and the directory where the class version of the program is stored is /afs/andrew/cs/15-211/bin , you could modify your search path by adding the following line to your .login file somewhere after the source /usr/local/lib/global.login line:

set path=(/afs/andrew/cs/15-211/bin $path)

verything about this line is the same as the other example except that a directory has been added at the beginning of the system path.

Last Updated: 11/7/05