bug-bash
[Top][All Lists]
Advanced

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

Re: "cd .." when WD unlinked gives wrong behaviour


From: Chet Ramey
Subject: Re: "cd .." when WD unlinked gives wrong behaviour
Date: Tue, 22 Feb 2005 21:01:58 -0500
User-agent: Mozilla Thunderbird 1.0 (Macintosh/20041206)

Chet Ramey wrote:
        https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=149079

        When the working directory has been unlinked, "cd .." should
        give an error exit status, but instead exits with code 0.
        Additionally, "pwd" (the built-in) appends "/.." to the
        previous working directory, rather than giving an error as it
        previously did.


Odd.  It only works this way on Linux.  MacOS X, FreeBSD and BSD/OS behave
as you expect.

Solaris doesn't allow the rm to work at all.

I will look into it further.

OK, I looked.  Here's what happens.  Bash tries to canonicalize the
directory name in the default logical mode.  Along the way, it tries
to verify the existence of each directory (e.g., to avoid the
/tmp/notthere/.. problem).  This canonicalization fails.

Ordinarily, cd might return failure right there.  Bash tries one more
time with the exact directory argument, passed straight to chdir(2).
In this case, this results in a call to chdir(".."), which, on Linux
(at least the version of Red Hat I have) succeeds (huh?).  This call
fails on the other systems I tried.

Well, once the chdir succeeds, bash has to recanonicalize the pathname
somehow.  Since the chdir succeeds, bash assumes that it can simply
call getcwd and get the right directory name, but that fails (the error
message).  Stuck, bash leaves $PWD set to the uncanonicalized name.

Since the chdir succeeded, cd returns 0.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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