69

Possible Duplicate:
How linux handles multiple path separators (/home////username///file)

Do cd dir/subdir/ and cd dir/subdir// mean the same thing in UNIX?

Will the latter work out? Does the difference have any special meaning for cd, mv, ls, or for any other command, for that matter?

Lucas
  • 119
San
  • 907
  • 1
    See also http://unix.stackexchange.com/questions/1910/how-linux-handles-multiple-path-separators-home-username-file The question asks about Linux but Gilles' answer covers more. – Steven D Apr 25 '11 at 20:00

1 Answers1

77

Actually it means nothing and is ignored.

This often happens when output from multiple places is combined and it isn't clear who's job it is to add the slashes, so both parties do it and you end up with two of them. Semantically in the case of a directory path is has no meaning and will be ignored by most programs.

There are other situations in the unix world where they have meaning. Sometimes at the start of a path they could trigger a search for a samba path instead of a local file system path, or after a protocol in nfs they can indicate a hostname, however particularly in the case of a trailing slash like you gave as an example, it shouldn't matter much.

For the sake of your sanity as an administrator or programmer you should still avoid these cases wherever possible. You never know when something will be parsed incorrectly, but if one comes your way don't worry about it.

Caleb
  • 70,105
  • 1
    Exactly, I wanted to know whether I can keep it as double or single. i.e. double works on the current shell, but am not sure it will work on all the environments. So, it's better to have it single, then. Thanks a lot. – San Apr 25 '11 at 09:33
  • 5
    I suppose the difference is that anything operating on the file system will usually discern the reference to the same folder, but anything doing string matching on your path and not actually parsing it and looking at the disc might see this as different file. For example if you were comparing two files lists, you would want to normalize them by removing duplicate '/'s. If you are passing the string to cd, it won't care. – Caleb Apr 25 '11 at 09:37
  • 5
    I believe POSIX specifies any number of consecutive slashes collapse into one, but I'm uncertain, I do know both Linux and FreeBSD do it in the kernel. It's not the shell that cares. The cases where multiple slashes affects the interpretation are not local filenames. The example caleb gives of a samba path is actually a UNC path and it how Windows (which does not allow multiple slashes) interpret the path. This does not occur normally on UNIX systems as they don't natively support UNC paths. URLs are a different matter and multiple slashes do affect interpretations. – penguin359 Apr 26 '11 at 05:51
  • Why isn't this expanded to include 3 in a row then? If you have $PATH/$OTHERPATH and $PATH = /etc/ and $OTHERPATH = /apt/ then wouldn't this result in "/etc///apt/" ? – Aaron Franke Oct 28 '16 at 04:18
  • it can be corrected by tweaking your path string like path=${path%/} – splaisan Mar 22 '19 at 11:35
  • Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266 "Multiple successive slashes are considered to be the same as one slash. " – ADJenks Apr 10 '19 at 22:39