coreutils
[Top][All Lists]
Advanced

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

Re: basename BSD compatibility and filter mode


From: Eric Blake
Subject: Re: basename BSD compatibility and filter mode
Date: Wed, 07 Mar 2012 07:01:50 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1

On 03/07/2012 05:48 AM, Pádraig Brady wrote:

> There is also a backwards compatibility subtlety.
> 
> $ src/basename a-a -a
> a-a
> $ basename a-a -a
> a

Ouch.

> 
> The following should address it and also have the
> benefit of short circuiting argument scanning.

Except that this _also_ breaks consistency; you could argue that given
the behavior of most GNU utilities, that

$ basename a --help

should output help text, rather than 'a'.  If a user really wants to use
'-a' as the suffix, then POSIX suggests that they use:

$ basename -- a-a a

But, since older basename didn't take any options except --help or
--version, we already have this in coreutils 8.15:

$ src/basename a --help
a

So I agree with this fix as being a way to preserve older behavior, even
if it is not consistent behavior.


> +++ b/tests/misc/basename
> @@ -50,6 +50,7 @@ my @Tests =
>       ['k', qw(aa a),       {OUT => 'a'}],
>       ['l', qw(-a a b),     {OUT => "a\nb"}],
>       ['m', qw(-s a aa ba ab),  {OUT => "a\nb\nab"}],
> +     ['n', qw(a-a -a),     {OUT => 'a'}],

I also think that you need to add another line to this test to ensure we
don't change our minds regarding 'basename a --help'.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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