A "POSIX compliant system" is a little vague in the real world, unfortunately. POSIX covers parts of the command set, the shell, the file system, the system calls, a threads interface, and more all through different sections and subsections of the standard. Many systems are POSIX compliant but with extensions, or have POSIX-compliant parts living alongside non-compliant or extended parts.
At the beginning of the string, //
may be treated specially in some systems under some circumstances.
For the rest of the string, replacing /././
with /./
or just /
should be equivalent on a POSIX system or a system interfacing to a POSIX-compliant subsystem. Likewise, in most cases anywhere except the beginning of the string //
or more forward slashes back to back can be collapsed to just /
.
However, some things will still trip you up. While the shell and FS may treat /foo//bar
the same as /foo/bar
, something like a web server pointed to serve files out of the file system might not treat them the same on the URL side, and a web cache in front of that probably won't. That's because while mapping from URLs to files in the FS might look straightforward, there are places where one standard and another don't necessarily map exactly as one would naively guess. Other network layers in front of an FS may cause similar edge cases.
In particular I'm reminded of caching with Varnish in front of an Apache server serving static files, when my team discovered /foo//bar
and /foo/bar
in our configuration would initially cache the same backend file, but to two different cache objects with two different cache TTLs. Using the Varnish config to rewrite to the canonical form solved that.
//./
may technically be interpreted differently from the transformed one starting with//
. See also On what systems is //foo/bar different from /foo/bar?. I suppose a real answer would discuss the path canonicalisation that thecd
utility does. – Kusalananda Sep 16 '22 at 09:03//item/
differently to/item/
. – Chris Davies Sep 16 '22 at 09:11//./somewhere
be the same as/somewhere
in Cygwin? Or different from//somewhere
? – Fravadona Sep 16 '22 at 10:46//
is a hostname. For example,ls -d //./tmp
returnsls: cannot access '//./tmp': No such file or directory
butls -d /tmp
is successful. Alsols -d //$(hostname)/
is successful (after a fashion). – Chris Davies Sep 16 '22 at 11:07//$(hostname)
and//./$(hostname)
should be equivalent, right? – terdon Sep 16 '22 at 12:05.
as localhost (true for parts of Windows networking) then your suggestions could be equivalent to/
and/$(hostname)
. – Chris Davies Sep 16 '22 at 12:18//
, it also means that you can't change something like/.//foo
into//foo
. – ilkkachu Sep 16 '22 at 13:06/./
has special meaning to rsync. – spuck Sep 16 '22 at 17:57