How does Unix read a path name with two consecutive slashes? (e.g. /home/user//mystuff) How does Unix read a path name with two consecutive slashes? (e.g. /home/user//mystuff) unix unix

How does Unix read a path name with two consecutive slashes? (e.g. /home/user//mystuff)


Unix shells and kernels happily handle this, as well as things like "/firstpart/./secondpart", but generally you don't make trailing slash a part of the variable value to make path concatenation expressions look nicer: ${firstpart}/${secondpart} rather than ${firstpart}${secondpart}.

In scripts on Linux the readlink command line tool can be used to normalize file names.


It's perfectly fine. Repeated slashes are treated as one by Unix systems, so always add one.

my $prefix = "/home/user";  # Or "/home/user/"my $suffix = "mystuff";my $dir = "$prefix/$suffix";

But if you want a canonised path for whatever reason (e.g. it's going to be displayed to a user), you can use:

use Path::Class qw( dir );my $prefix = dir("/home/user");  # Or "/home/user/"my $dir = $prefix->subdir($suffix);say $dir;

Whether you start with /home/user, /home/user/ or even ///home///user///, you end up with:

/home/user/mystuff