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 11:52, Richard Hartmann <richih.mailinglist@xxxxxxxxx> wrote:
> On Tue, Mar 27, 2012 at 16:34, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>> However, I've always been a little puzzled about the decision to set
>> $PWD to "." in this case.  Bash remembers the relative location:
> Just to make sure this does not get lost, do we agree that not
> changing $PWD to a literal dot would make sense? Escalating the ENOENT
> to the user is probably the best approach.

Weird, when I try making a directory and remove it, I can still cd ..
to the parent... I can even cd into the dir with another shell (via
/proc/$$/cwd), and cd .. to the correct parent dir from that other

> Various external commands such as "ls" silently exit with success on a
> non-existent current working directory, I think that may have been the
> model for the original behavior.

They succeed silently because the directory exists and is empty.
% ls
% pwd
% stat .
  File: '.'
  Size: 6         	Blocks: 0          IO Block: 4096   directory
Device: 811h/2065d	Inode: 299438815   Links: 0
Access: (0755/drwxr-xr-x)  Uid: ( 1000/ mikachu)   Gid: (  100/   users)
Access: 2012-04-02 12:12:26.696856559 +0200
Modify: 2012-04-02 12:12:26.696856559 +0200
Change: 2012-04-02 12:12:31.260107270 +0200

When I try bart's double-directory trick, I can still cd .. twice and
get back to the correct grandparent directory.

Mikael Magnusson

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