2019-06-05 13:16:14 -0700, Jefferson Carpenter:
> Not quite - if basename begins with one or more slashes that
> could still cause incorrect behavior.
>
> The closest would be echo ${dirname%/}/${basename##*(/)} with
> the bash extglob option enabled.
(note that's originally a ksh operator)
Appending a relative path to an absolute or relative path make
sense, but not an absolute path to any path (absolute or
relative)
What should the result be?
Note how the languages that already have a path joining operator
disagree on that.
rubyjoin() { ruby -e 'puts File.join(ARGV)' -- "$@"; }
pythonjoin() { python -c 'import os, sys; print(os.path.join(*sys.argv[1:]))'
"$@"; }
perljoin() { perl -MFile::Spec -le 'print File::Spec->join(@ARGV)' -- "$@"; }
~$ perljoin a/b /c/d
a/b//c/d
~$ pythonjoin a/b /c/d
/c/d
~$ rubyjoin a/b /c/d
a/b/c/d
~$ perljoin //host /a/b
/host//a/b
~$ pythonjoin //host /a/b
/a/b
~$ rubyjoin //host /a/b
//host/a/b
~$ pythonjoin // /a
/a
~$ rubyjoin // /a
/a
~$ perljoin // /a
//a
If POSIX were to specify such an utility (but I'm not sure it
would as there's no prior art that I know, and there doesn't
seem to be a strong demand for it), I guess it would leave it
unspecified if any but the first argument was an absolute path.
It may have to leave it unspecified if the first argument starts
with two (but not more) / characters.
The behaviour for empty arguments would probably also have to be
left unspecified.
--
Stephane