Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: cd, pwd and symlinks



Bart Schaefer wrote:
>On Sep 28, 12:07pm, Peter Stephenson wrote:
>} There's some reason why the code was changed
>} to do all changes with absolute path --- maybe to simplify it, hur hur.
>
>As far as I can tell, this is something Zefram changed between 3.1.2 and
>3.1.3, for which no patch was ever posted.

I'm pretty sure it's not.  That's one of the areas of the shell that I
studiously avoided changing.

If I'd designed the shell from scratch, it would match the underlying OS
behaviour, and consequently $PWD wouldn't exist, or at least not in the
form we have it.  $PWD is really an abomination, giving the impression of
an absolute directory structure, which in fact doesn't exist.  Given that
we have to support it, there are basically two sensible ways for it
to work:

1. cd maps directly onto chdir(), doing everything the way the
   filesystem says.  $PWD has no direct effect -- it is equivalent to
   $(pwd), recalculated every time it is referenced.  It always searches
   for a valid absolute pathname referring to the current directory.
   The user must accept that it will sometimes fail (yielding "."),
   and that the pathname returned will not necessarily remain valid,
   but it will always be valid at the moment it is evaluated.

2. $PWD is the shell's canonical idea of its current directory.  cd with
   a relative pathname does text substitution using $PWD, and then does
   a chdir() to the resulting absolute pathname.  pwd just gives $PWD,
   and has an option to do a /bin/pwd-style search instead.  The user
   must accept that the current directory may not be accessible under
   the name in $PWD, and that relative filenames in a cd command have
   completely different semantics from relative filenames everywhere else.

Until 3.1.6, we had a pretty consistent 2.  Now we have a mixture of the
two styles, which isn't working, and making it more complicated isn't
going to help.  Let's just have the two ways of working, with an option
to switch between them.

-zefram



Messages sorted by: Reverse Date, Date, Thread, Author