Thread: Where is '//'?

  1. #1
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875

    Where is '//'?

    This is a dumb question that I thought of when working whilst tired and more than once when meaning to 'cd ..' (go up one directory) did a 'cd //'. Where exactly does that leave you? pwd just gives the obvious and frankly useless:
    Code:
    jeff@jeffdeb://$ pwd
    //
    Now doing an ls shows me to be in the root (not /root but /) but there has GOT to be some differences between /root and //. Anyone with a clue?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by jeffcobb View Post
    This is a dumb question that I thought of when working whilst tired and more than once when meaning to 'cd ..' (go up one directory) did a 'cd //'. Where exactly does that leave you? pwd just gives the obvious and frankly useless:
    Code:
    jeff@jeffdeb://$ pwd
    //
    Now doing an ls shows me to be in the root (not /root but /) but there has GOT to be some differences between /root and //. Anyone with a clue?
    You're seeing the shell's (not quite so intelligent) caching of the current directory. If you actually called getcwd(), the system call, it would return "/".

    UNIX path parsing treats multiple slashes as a single slash. You should be in the root dir.

    EDIT: Hmm. Maybe there's more to it. When I "cd //" I see the same thing you are seeing. But "cd ///" takes me to plain old "/". Not sure now!

    Here's what Python says:

    Code:
    scott@VM-Kubuntu-1:~$ cd //
    scott@VM-Kubuntu-1://$ python
    Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> print os.getcwd()
    /
    Python uses the real getcwd() call, so I think it really is just "/" and you're seeing some shell funniness.
    Last edited by brewbuck; 07-12-2010 at 06:33 PM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    It looks like you are using Bash, and it does not quite know what to make of your cd. In zsh, you can do cd //, and it takes you to /, as well as listing / (as opposed to //) in the shell prompt. Also, pwd gives /, and not //. It may seem a little odd, but so is (in my opinion) the output of ls -la in root, i.e.,

    Code:
    drwxr-xr-x  21 root root  4096 2010-07-04 01:15 .
    drwxr-xr-x  21 root root  4096 2010-07-04 01:15 ..
    There is no parent directory, yet it lists it. I know I read the explanation of that somewhere, and no doubt there is a very good reason for it. But at first glance, it does not seem very intuitive. Anyway, by doing // you are saying go to the directory / relative to / - As you can see, from my listing above, that directory does exist, and Bash took you there. I vote that it is a bug of some sort though.
    Last edited by kermit; 07-12-2010 at 06:51 PM.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by kermit View Post
    There is no parent directory, yet it lists it. I know I read the explanation of that somewhere, and no doubt there is a very good reason for it. But at first glance, it does not seem very intuitive. Anyway, by doing // you are saying go to the directory / relative to / - As you can see, from my listing above, that directory does exist, and Bash took you there. I vote that it is a bug of some sort though.
    The parent directory of the root directory is the root directory. That is defined by POSIX, and just the way it is. The idea of a special directory which has no parent, seems even more confusing than a directory which is its own parent. Programs which used ".." would then have to continually check whether a given directory is the root directory in order to avoid errors.

    Really, I think the shell is caching the current directory and somehow "//" makes it do something weird. Try tcsh instead:

    Code:
    scott@VM-Kubuntu-1:~$ tcsh
    VM-Kubuntu-1:~> cd //
    VM-Kubuntu-1:/> pwd
    /
    It's clearly just weirdness of the shell. I hesitate to call it a bug, but if it is, it's a bug in bash.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I thought it might have something to do with network shares like //mybox but it is more-likely a bug in bash. Hurts nothing, just made me curious....thanks for the braincells on this guys...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed