While working on my {base,dir}name patches for // handling, I
also spent some time editing tests/basename/basic to and creating
tests/dirname/basic.  In the process, I came across the other
implementation-defined behavior, namely what "basename ''"
should return.  POSIX allows either '' or '.'.  (For dirname, POSIX
is explicit that the dirname of the empty string is '.').

One argument is that POSIX intends for "cd $(dirname $name);
ls $(basename $name)" to succeed for all valid $names, but since
$name='' is not a valid filename, it should cause a failure.  The
counter-argument is that for compatibility, (at least for
/usr/xpg4/bin/basename on Solaris 8), older systems have already
been outputting '.', even though the dirname/basename sequence
creates a valid filename out of an invalid one, and since the POSIX
Examples section for basename states "The basename utility is not
expected to make any judgements about the validity of string as a
pathname; it just follows the specified algorithm to produce a result
string."

Currently, coreutils returns ''.  I don't want to change this unless
anyone else thinks it should be changed for compatibility.  Comments?

--
Eric Blake


_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to