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   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to