In bash if you cd to // your pwd will be //, but if you cd to / or ///+ your pwd will be /. Is there a reason for this or is it just a weird bug?
I have tried this in osx and ubuntu.
From the Bash FAQ:
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'.
Though the answer was correct on the data it gave, it didn't quite answer the question asked.
The shell is normalizing the path. It does:
You can verify this with strace, which will see what is actually passed into the syscall
strace -o /tmp/strace.out bash -c "cd ///tmp" grep chdir /tmp/strace.out # will give chdir("/tmp") strace -o /tmp/strace.out bash -c "cd ///tmp/../etc" grep chdir /tmp/strace.out # will give chdir("/etc")
The shell does the path normalization before it even tells the system to change the dir