bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug when 'cd ..' to a directory who's parent has been deleted


From: Greg Wooledge
Subject: Re: bug when 'cd ..' to a directory who's parent has been deleted
Date: Mon, 8 Feb 2016 10:17:45 -0500
User-agent: Mutt/1.4.2.3i

On Mon, Feb 08, 2016 at 10:09:29AM -0500, Chet Ramey wrote:
> On 2/8/16 9:59 AM, Andreas Schwab wrote:
> > Chet Ramey <chet.ramey@case.edu> writes:
> > 
> >> `cd ..' should fail, since the parent no longer exists, and the pathname
> >> canonicalization should fail, since there's presumably no longer a valid
> >> path to reach the current directory.  No value for $PWD is correct.
> > 
> > ${PWD%/*} would be a reasonable value.  FWIW, this is what ksh uses in
> > this case, it doesn't fail.
> 
> Why would that be more reasonable than anything else?  It references a
> path that doesn't exist.

Bash and ksh both behave somewhat similarly:

imadev:~$ mkdir -p /tmp/a/b
imadev:~$ cd /tmp/a/b

(in another window)
$ rm -rf /tmp/a

(in the first window)
imadev:/tmp/a/b$ cd ..
bash: cd: ..: No such file or directory
imadev:/tmp/a/b$ cd /tmp
imadev:/tmp$ ksh
$ mkdir -p /tmp/a/b
$ cd "$_"

(in another window)
$ rm -rf /tmp/a

(in the first window)
$ cd ..
ksh: ..:  not found
$ pwd
ksh: pwd: permission denied
$ echo "$PWD"
/tmp/a/b

That's ksh88, for what it's worth.

I can't really imagine a scenario where the current directory exists
but the parent does not.  So I'm merely assuming that the original
poster meant BOTH the current and parent directories are gone.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]