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

Re: `cd .` in non-existent directory leads into weird corner case



On 2 April 2012 12:33, Peter Stephenson <Peter.Stephenson@xxxxxxx> wrote:
> On Mon, 2 Apr 2012 12:15:59 +0200
> Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> Weird, when I try making a directory and remove it, I can still cd ..
>> to the parent...
>
> That's not weird; the shell remembers PWD because by default it changes
> directory logically rather than physically, i.e. retaining symbolic
> links in the path, so it changes to the parent directory by what
> amounts to 'cd $PWD:h'.

How does this explain that it works from the other shell that never
knew what $PWD was? I'm sticking with my theory that the directory
exists until we leave it :). I called it weird because obviously it
doesn't work for richih, as one can see in his transcript.

> What you get with CHASE_LINKS or cd -P is another matter, since the
> ability to take account of symbolic links means the whole logic is
> rather baroque, but I'd vaguely expect it either to fail or fail to
> resolve the physical directory and default to trimming PWD.  (What it
> does and what it should do are again not necessarily identical.)

Ah, and I do have both CHASE_LINKS and CHASE_DOTS set, which explains
it. When I unset them, zsh indeed stays in mysterious '.' land
forever. With them set, it properly follows the physical .. entries
back to the parent directory.

[so the first part has chase_* set]
~% mkcd foo
~/foo% rmdir ~+
~/foo% cd .
.% cd ..
~% mkcd foo/bar
~/foo/bar% rmdir ~+ ~+(:h)
~/foo/bar% zsh -f
.% pwd
.
.% cd ..
.% pwd
.
.% cd ..
.% pwd
.
.% cd ..
.% pwd
.
.% cd -P ..
.% cd -P ..
~%

-- 
Mikael Magnusson



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