Directory "//"

GuiSilva02

New Member
Joined
Feb 21, 2022
Messages
5
Reaction score
6
Credits
48
Hi,

An expert on Unix Systems asked me about why "cd //" access to a directory named "//" more slashes will access to a directory "/".

The question is why "//" exists and what it is used for?

I got some answers for example:

"//" is nothing and is ignored.

"//" is used for compatibility with older Unix Systems.

"//" is an extern way to access "/".

This expert said that is all wrong.

Can someone help and explain the reason for the "//".

Thank you
 


They have also asked here:

 
That doesn’t happen on Solaris, Darwin, or OpenBSD.
So it's a shell feature. It happens in bash where cd is a builtin, so I guess the bash devs decided to allow it to occur, but still keep the user in the only "arguable logical directory" that // could point to, rather than give the usual "No such file or directory". The answer will likely be in the bash code, or the code of the shells that perform this way. I haven't looked though.
 
So it's a shell feature. It happens in bash where cd is a builtin, so I guess the bash devs decided to allow it to occur, but still keep the user in the only "arguable logical directory" that // could point to, rather than give the usual "No such file or directory". The answer will likely be in the bash code, or the code of the shells that perform this way. I haven't looked though.
hmm I tried many answers and he keeps telling me that I am wrong, so is more than that
 
I got some answers for example:

"//" is nothing and is ignored.

"//" is used for compatibility with older Unix Systems.
You've got good answers before. Why do you doubt them? These websites (here, here, here, and here) confirm what you've already found. If you check my links, they also link to POSIX and Unix specifications that are the basis of this behavior.

The Bash author, Chet Ramey, identified above by @NorthWest, also explains this in his FAQ, quoting here:
E10) Why does `cd //' leave $PWD as `//'?

POSIX.2, in its description of `cd', says that *three* or more leading
slashes may be replaced with a single slash when canonicalizing the
current working directory.

This is, I presume, for historical compatibility. Certain versions of
Unix, and early network file systems, used paths of the form
//hostname/path to access `path' on server `hostname'.


That doesn’t happen on Solaris, Darwin, or OpenBSD.
It *DOES* happen on OpenBSD if you install and use Bash instead of the default ksh. I've just confirmed this on OpenBSD 7.0. So while Bash keeps this behavior for "historical compatibility," the authors of ksh have chosen not to do so.
 
You've got good answers before. Why do you doubt them? These websites (here, here, here, and here) confirm what you've already found. If you check my links, they also link to POSIX and Unix specifications that are the basis of this behavior.

The Bash author, Chet Ramey, identified above by @NorthWest, also explains this in his FAQ, quoting here:




It *DOES* happen on OpenBSD if you install and use Bash instead of the default ksh. I've just confirmed this on OpenBSD 7.0. So while Bash keeps this behavior for "historical compatibility," the authors of ksh have chosen not to do so.
I already answered that to the expert before but he keeps telling me that I am wrong and is not that. That question is from a certification exam and that expert got 100% on the certification. I think that I will just ask him now because I cant think on more possibilities for that question.
 
When you do find the 'correct' answer, please be sure to come back and let us know. I'm now a bit curious and I've declined my chance to speculate.
 
I think that most authoritative answer that you will get will be available on the gnu.org mailing list for bash where at least one of the major bash devs is a regular contributor. Here's his home page where you can email him: https://tiswww.case.edu/php/chet/
From him I got that:

"It doesn't. It's not a separate directory on your system. On Unix systems,
any number of consecutive slashes is the same as a single slash, and can
be collapsed to a single slash as part of pathname canonicalization
(transforming a pathname to a canonical form, which usually means removing
`.' and sometimes `..' and collapsing multiple consecutive slashes). For
instance, ////usr/////bin////awk is the same as /usr/bin/awk. So, without
any special cases, `//' is the same directory as `/'.

`cd' performs pathname canonicalization on its argument, and, if the chdir
is successful, stores the resultant pathname in the `PWD' variable.

However, a leading `//' is a special case. When you do pathname
canonicalization, like `cd' does, you leave a leading `//' alone.

That's because there are systems for which the special pathname starter
`//' introduces a network filesystem reference. It's something like
//hostname/path/on/host or //group/host/path/on/host. Cygwin does this to
encode Windows UNC paths, for example.

If a user wants to reference a file in such a distributed system, you
don't want to rewrite the pathname to prevent that."

So I think that what we already said is just a incomplete answer.
 


Top