
Simplify Changing Directories #14
Chapter 2, Console
|
47
HACK
Assuming you have defined CDPATH as shown in the previous example, now
you should be able to type this command, (almost) no matter what your cur-
rent directory might be:
$ cd chapter2
The command should take you immediately to the directory /docs/pub/
books/oreilly/linuxhacks/chapter2.
The Catch
Remember I said you’re obsessive about organization? Suppose you also cre-
ated the following directories according to the same pattern mentioned earlier:
/docs/pub/books/oreilly/bsdhacks/chapter1
/docs/pub/books/oreilly/bsdhacks/chapter2
/docs/pub/books/oreilly/bsdhacks/chapter3
Naturally, you have to add a new path to your
CDPATH environment variable:
$ export CDPATH=:.:/docs/pub/books/oreilly/linuxhacks:/docs/pub/books/
oreilly/bsdhacks
As with the PATH environment variable, you separate different search paths
with a colon. The system searches through each path from left to right. Now
issue this command:
$ cd chapter2
Where do you think it takes you? It puts you in the same place as before, /docs/
pub/books/oreilly/linuxhacks/chapter2.Thatisnot what you expected or
desired. But it happened because the
cd command searches the CDPATH envi-
ronment variable paths from left to right. It searched the linuxhacks location
first and found chapter2. So, that’s where it assumed you wanted to go.
The Solution
One solution is to avoid being obsessive about standardizing ...