When you type the command cd
foo, the shell first tries to go to the
exact pathname foo. If that
doesn't work, and if foo
is a relative pathname, the shell tries the same command from every
directory listed in the cdpath. (If you use
ksh or sh, see the note at the
end of this article.)
Let's say that your home directory is
/home/lisa and your current directory is
somewhere else. Let's also say that your
cdpath has the directories
/home/lisa,
/home/lisa/projects, and
/books/troff. If your cd
foo command doesn't work
in your current directory, your shell will try cd
/home/lisa/foo, cd
/home/lisa/projects/foo, and
cd /books/troff/foo, in
that order. If the shell finds one, it shows the pathname:
% cd foo
/home/lisa/foo
%
If there is more than one matching directory, the shell uses the
first match; if this isn't what you wanted, you can
change the order of the directories in the
cdpath.
Some Bourne shells don't show the directory name.
All shells print an error, though, if they can't
find any foo directory.