Subject: bug#6124: basename/dirname are not POSIX compliant on arg starting with a dash

From: Eric Blake <[email-masked]>
Date: Thu, 06 May 2010 08:29:57 -0600

On 05/06/2010 08:24 AM, Vincent Lefevre wrote:
>>     Default Behavior: When this section is listed as "None.", it means
>> that the implementation need not support any options. Standard utilities
>> that do not accept options, but that do accept operands, shall recognize
>> "--" as a first argument to be discarded.
> 
> OK, an alternative way would be that an exception is added to POSIX,
> just like for "echo".

Please no.  echo has an exception precisely because it has historical
baggage, and that is what makes echo so pitiful that POSIX itself states
that printf(1) is more portable than echo(1).  Relatively newer
applications, like basename and dirname, that were first written in an
age when consistency was more important, should not be burdened with the
historical baggage of ancient echo(1).  And changing it now is too late;
just as you argue about the number of broken scripts that are not robust
because they failed to use --, you have to also consider the number of
correct scripts that have been written with the correct assumption that
basename and dirname accept --: it has been 9 years since POSIX 2001
first codified that behavior.

Besides, we would much prefer to keep 'basename --help' as a GNU
extension.  Not having 'POSIXLY_CORRECT=1 /bin/echo --help' give useful
help is an annoyance that we would rather avoid repeating.

> 
> However, if extensions are allowed, this would mean that many scripts
> would have to be fixed.

Yes, many broken scripts need to be fixed.  But that is the fault of
those broken scripts, not coreutils.

-- 
Eric Blake   [email-masked]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org