Re: CDPATH and shell builtins. Need explanation of how it works.
From: David Thompson (dat1965_at_yahoo.com)
Date: Fri, 17 Oct 2003 18:23:33 GMT
"Barry Margolin" <email@example.com> wrote
> J Peterman <firstname.lastname@example.org> wrote:
> >What I am thinking is that when you type in "cd pathname", the function
> >should search all the paths listed in the CDPATH environment variable,
> >if it finds it, make the current directory "pathname".
> >Is this correct?
> Not quite. It tries to find "pathname" relative to each of the paths in
> CDPATH. E.g. if CDPATH contains /dir1/dir2:/other/dir, it will look for
> /dir1/dir2/pathname and /other/dir/pathname. If it finds one of them, it
> will make the current directory that full path.
Yeah, and it cd's to that directory despite the specified
pathname existing in your current directory. Which is why
I eventually decided CDPATH wasn't all that useful for my
purposes. I eventually found CDPATH annoying. Why?
Observe this ksh93 simple test scenario,
$ unalias cd
$ export CDPATH
$ mkdir /tmp/dummy
Now type this innocent sequence,
$ mkdir dummy
$ cd dummy
and observe, the resulting chdir annoyingly ignored the
fact that 'dummy' exists in the current directory,
I'd prefer ksh93 to cd to $HOME/dummy. I don't think
retraining my fingers to do,
$ cd ./dummy
was worth putting the ./ in front of *every* cd command,
just to keep CDPATH from hijacking my intentions. I'd
always prefer to just chdir to the specified path relative
to the current directory, if it exists, and only use the
CDPATH if it's not found. Forcing my intentions known and
typing ./ to mean current directory became annoying, but
using CDPATH means you add ./ alot to your cd commands. Ie,
for me, using CDPATH forced me to become explicit (overly so)
on what used to be an assumed feature of the cd command.
The design of CDPATH is that it takes precedance over
looking in the current directory, do you know of any way
to reverse this search order? I'd want CDPATH consulted
only as a last resort.
-- David Thompson Foster City, CA