Re: whats this?!

[ Available lists | Index of freebsd-questions | Month of Dec 2001 | Week of 14 Dec 2001 | Raw email | View thread | Wrap long lines | Reply | Tag ]
From
Cliff Sarginson <cliff@raggedclown.net>
Date
14 Dec 2001 22:39:20
Subject
Re: whats this?!
Message-ID
20011215063913.GA7022@raggedclown.net

In reply to
References to

[ Hide this part ]
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



Elapsed time: 0.210 seconds