14.13 Which Directory Am I in, Really?
The C shell, and some other shells too, keep their own idea of what your
current directory is.
The
csh
will give you the current directory's absolute pathname in
Why?
Because the
cwd
variable was added before many versions of UNIX
had
symlinks (
18.4
)
(symbolic links).
As article
18.7
explains,
symlinks can point to directories any place else on the filesystem or
even (for some UNIXes) directories on another computer.
Poor
cwd
couldn't cope: it assumed that the current directory was the
name of the symlink itself (instead of the directory that the link points to).
That led to problems like the one below:
cd
ing to a "directory" named
wpa
that's actually a symlink to
/work/pwrtools/articles
.
The value of
/home/jerry% By now, a lot of C shells have a variable named hardpaths ; the bash variable is nolinks . If you set the shell variable (usually in your shell setup file ( 2.2 ) ), the shell won't be fooled by symlinks. Watch:
/home/jerry/wpa%
Setting
hardpaths
or
nolinks
makes the shell do extra work,
so don't bother with it unless you use The dirs ( 14.6 ) command has the same problem. Setting hardpaths or nolinks helps there, too. If your system has symlinks but your shell doesn't recognize a variable like hardpaths , here are workarounds for the .cshrc file:
alias setprompt 'set prompt="${cwd}% "' alias cd 'chdir \!* && set cwd=`/bin/pwd` && setprompt' alias pushd 'pushd \!* && cd .' alias popd 'popd \!* && cd .'
When you
cd
, that alias resets the
cwd
variable to the
output of
/bin/pwd
, then resets the prompt to the new
cwd
.
Using
pushd
or
popd
(
14.6
)
runs the
cd
alias, too - this changes
to the current directory ( Whew. Are symlinks worth the work? (I think they are.) - |
|