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.ra...@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.