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

Re: `exec env -i OLDPWD=$OLDPWD zsh` doesn't work

(This bit moved to zsh-workers.)

OLDPWD seems to be slightly weirdly implemented at the moment.  There's
an internal variable storing it, but that's not explicitly tied to a
shell variable; instead when the internal variable gets changed
the shell variable also gets changed.  So the internal variable isn't
changed if you change the shell variable, which there's nothing
stopping you doing, i.e. you may look at $OLDPWD and think that's where
you're about to change to whereas ~- will actually take you somewhere

This also means that where the code says (at initialisation)

    oldpwd = ztrdup(pwd);  /* initialize `OLDPWD' = `PWD' */

it doesn't do anything of the kind, because OLDPWD is only ever set on a
cd, as far as I can see.  It does change what ~- will do, however.

Because OLDPWD isn't actually managed the way you expect, there's a
kludge when changing directories that if the variable's the wrong type
it's simply unset and made non-readonly --- except it isn't made
non-readonly if it was already scalar but readonly.

This all seems a bit substandard, not to say amateurish.  It might
be down to a desire to keep OLDPWD from being special --- but that
doesn't work because it's use when changing directory is unconditional,
and unless you never change directory you can't do anything else with
it.  So as far as I can see it could just as well be a proper special
variable tied to the internal one, for which there's already an API.

There may be some history I've forgotten about.


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