Date: Sat, 15 Dec 2001 07:39:13 +0100 From: Cliff Sarginson <cliff@raggedclown.net> To: Freebsd-questions <freebsd-questions@FreeBSD.ORG> Subject: Re: whats this?! Message-ID: <20011215063913.GA7022@raggedclown.net> In-Reply-To: <20011213164200.N94620-100000@catalyst.sasknow.net> References: <200112132105.QAA16995@uce55.uchaswv.edu> <20011213164200.N94620-100000@catalyst.sasknow.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Dec 13, 2001 at 04:47:03PM -0600, Ryan Thompson wrote: > Nathan Mace wrote to Freebsd-questions: > > > type 'cd //' and then do a pwd. > > > > what causes this? found it by accident > > I think it's a parsing [bug|feature] in bash. Slashes are normally > condensed. At least, I have only noticed this peculiarity in bash. > The standard shells (sh, [t]csh) do not appear to be affected. > > Probably it is because bash tries to use "friendly" pathnames (i.e., > displays ~/username instead of /usr/home/username), thus circumventing > nice things like realpath(3). > > In any case, when bash actually passes the pathname to any of the > library path routines, the slashes WILL eventually get condensed, so > this shouldn't affect operation at all. > Out of curiosity I tried a few expriments, since I have noticed that bash does this, but only with 2 leading "/"s. It correctly throws away multiple slashes in subsequent elements of a path name. In tcsh you can also have multiple slashes anywhwere in a pathname and it just throws them away. Internally it also records what you typed in, with 2 leading slashes, but subsequent multiple occurences suppressed. Even more amusing is $OLDPWD, which faithfully copies $PWD when you cd. So if you manually set $PWD to something nonsensical, "pwd" still reflects where you really are. Now cd to somewhere else and try "cd -" it then does use OLDPWD and of course gets an error. I say of course, but it does some slightly odd that the shell does not remember the real old pwd, the externally visible one not being that robust a mechanism. The upshot of all this timewasting (by me!) is that multiple "//"s in pathnames are not illegal, they just get parsed out as empty components. i.e. "//" is the same as "/./" practically speaking. However an absolute pathname is quite a diferent animal to a relative one if you think about it. The shell does not need to know where it is to do a cd in this case. Hence the logic for an absolute pathname is probably seperate, or at least "special-cased" in the shell code. It looks as though this special case has a buggette in it. Practically speaking I guess it is inconsequential. Probably though PWD and OLDPWD should be read-only shell vars for robustness. I guess in the great scheme of things it doesn;t matter that much :) -- Regards Cliff To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011215063913.GA7022>