bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

basename '' semantics


From: Eric Blake
Subject: basename '' semantics
Date: Wed, 13 Jul 2005 23:26:56 +0000

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]