Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: `exec env -i OLDPWD=$OLDPWD zsh` doesn't work
- X-seq: zsh-workers 40349
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Subject: Re: `exec env -i OLDPWD=$OLDPWD zsh` doesn't work
- Date: Fri, 13 Jan 2017 15:19:37 +0000
- Cms-type: 201P
- In-reply-to: <20170113145919.GB4363@fujitsu.shahaf.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
- References: <CAM4j=kO9MSg-72LWog0N3OPumh8jy_xt4_T_fXEXAKQEk3eoXg__31721.773549407$1484300384$gmane$org@mail.gmail.com> <CGME20170113150404epcas4p2b15a4b2d8af580d4b38d8c69e13737a7@epcas4p2.samsung.com> <20170113145919.GB4363@fujitsu.shahaf.local2>
(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
else.
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.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author