in reply to Re: How to get the unique canonical path of a given path?
in thread How to get the unique canonical path of a given path?

/tmp/../../../tmp  ->  /tmp

Unless I'm very much mistaken, wouldn't that try to go two directories above the root before trying to find a tmp subdirectory of the non-existant location? In /tmp/../../../tmp, the first /tmp/.. pair resolves to just /, so that is effectively /../../tmp , but that path is rather meaningless, because you cannot `cd ..` from `/`.

Nevermind; ignore my objection from the spoiler. I just tried the cd /tmp/../../../tmp and found it did go to the /tmp directory. And perl -le 'use autodie; open my $fh, ">", "/tmp/../../../tmp/worked.txt"; print {$fh} "it worked";' works as expected as well, so apparently that weird notation is a perfectly-valid syntax. Sorry.

Replies are listed 'Best First'.
Re^3: How to get the unique canonical path of a given path?
by tybalt89 (Monsignor) on Jul 16, 2022 at 17:43 UTC

    It works because on a *nix system the root directory is pretty much defined by " .. is the same as . "