zsh-workers
 help / color / mirror / code / Atom feed
* Re: `exec env -i OLDPWD=$OLDPWD zsh` doesn't work
       [not found]   ` <20170113145919.GB4363@fujitsu.shahaf.local2>
@ 2017-01-13 15:19     ` Peter Stephenson
  2017-01-13 15:24       ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2017-01-13 15:19 UTC (permalink / raw)
  To: Zsh Hackers' List

(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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: `exec env -i OLDPWD=$OLDPWD zsh` doesn't work
  2017-01-13 15:19     ` `exec env -i OLDPWD=$OLDPWD zsh` doesn't work Peter Stephenson
@ 2017-01-13 15:24       ` Peter Stephenson
  2017-01-14  5:09         ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2017-01-13 15:24 UTC (permalink / raw)
  To: Zsh Hackers' List

On Fri, 13 Jan 2017 15:19:37 +0000
Peter Stephenson <p.stephenson@samsung.com> wrote:
> (This bit moved to zsh-workers.)
> 
> OLDPWD seems to be slightly weirdly implemented at the moment.

PWD is similar; it does *not* reflect the internal variable containing
the shell's internal notion of the current directory (never mind what
the system thinks is the current directory which is different again).

% (PWD=/foo/bar; print ~+)
/export/home/pws/src/zsh-git/code

pws


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: `exec env -i OLDPWD=$OLDPWD zsh` doesn't work
  2017-01-13 15:24       ` Peter Stephenson
@ 2017-01-14  5:09         ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2017-01-14  5:09 UTC (permalink / raw)
  To: Zsh Hackers' List

On Fri, 13 Jan 2017, Peter Stephenson wrote:

> 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

This is actually semantically necessary, as I recall.  There's no
prohibition on using OLDPWD and PWD as ordinary variables, as long as
you don't "cd" along the way.

And assigning to them is not supposed to behave like a "cd" or to
change the way "cd -" works, as far as I can tell.

Please don't make them into specials, we'll just have to find a way to
un-special them again for POSIX compatibility or something.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-14  5:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAM4j=kO9MSg-72LWog0N3OPumh8jy_xt4_T_fXEXAKQEk3eoXg__31721.773549407$1484300384$gmane$org@mail.gmail.com>
     [not found] ` <CGME20170113150404epcas4p2b15a4b2d8af580d4b38d8c69e13737a7@epcas4p2.samsung.com>
     [not found]   ` <20170113145919.GB4363@fujitsu.shahaf.local2>
2017-01-13 15:19     ` `exec env -i OLDPWD=$OLDPWD zsh` doesn't work Peter Stephenson
2017-01-13 15:24       ` Peter Stephenson
2017-01-14  5:09         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).