6

Tested on a debian and debian-based:

$ cd // && pwd && ls
//
bin   build  dev  home ...

Why is the path // a valid path?

Rex
  • 7,895
  • 3
  • 29
  • 45
bux
  • 626
  • 2
  • 6
  • 20

2 Answers2

12

According to the POSIX specification:

A pathname that begins with two successive slashes may be interpreted in an
implementation-defined manner, although more than two leading slashes shall be
treated as a single slash.

I'm guessing bash resolves the two slashes to a single slash, so they both mean the same thing. And according to the specification, cd /// should also give the same output.

You can check the inode number of the current directory using

stat -c "%i" .

and you'll notice that the inode number of / and // are the same.

  • I doubt bash does this. I rather think it is the kernel's job... – glglgl Apr 16 '14 at 10:54
  • 1
    The specific of // not necessarily = / is reserved for Windows POSIX environment for which // begins a UNC name. Cygwin also behaves this way. – joshudson Apr 16 '14 at 15:11
  • @joshudson Don't also forget that URI `/a/b/c` is a relative URI, while an URI `//a/b/c` is an absolute one, and `a` is the host name. – Joker_vD Apr 16 '14 at 16:48
5

This question has already been answered here.

On most POSIX systems, multiple slashes are simply ignored.

Spack
  • 1,604
  • 15
  • 22
  • 4
    We really do prefer that answers contain content not pointers to content. Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – user9517 Apr 16 '14 at 10:22