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: Jérémy Compostella
Subject: Re: basename BSD compatibility and filter mode
Date: Fri, 9 Mar 2012 15:20:03 +0100

2012/3/7 Pádraig Brady <address@hidden>:
> On 03/07/2012 02:02 AM, Pádraig Brady wrote:
>> On 03/04/2012 07:09 PM, Jérémy Compostella wrote:
>>>> [...]
>>>> I just logged onto an OS X box there and you're right:
>>>>
>>>> $ printf "%s\n" 1/1 2/2 | xargs basename
>>>> 1
>>>>
>>>> $ printf "%s\n" 1/1 2/2 3/3| xargs basename
>>>> 1
>>>> 2
>>>> 3
>>>>
>>>> However I think it's dangerous to do that.
>>>> If I was writing a script I would probably test with
>>>> 1 or 3 or more arguments. But the script would then fail if
>>>> given 2 args based on transient conditions.
>>>> I would not emulate that "feature".
>>> I do agree it's dangerous. I removed this "feature".
>>>
>>>>> [...]
>>>>> Eric Blake said:
>>>>>> It's been brought up before, and the consensus has always been that if
>>>>>> someone would write the patches, it would be worthwhile.  We do need
>>>>>> support for a -0 or some other way to do NUL-terminated filtering,
>>>>>> though.
>>>>> which conflict with the idea that this feature is not really worth. I'm
>>>>> a bit confused now ...
>>>>
>>>> Yes, I agreed with Eric that -0 was useful,
>>>> but on consideration if not processing stdin,
>>>> then I don't think it's of use.
>>> OK.
>>>
>>> I attached the patch. Feel free to comment.
>>
>> Thanks again for doing that.
>> I've made the following tweaks and will push early tomorrow.
>
> There is also a backwards compatibility subtlety.
>
> $ src/basename a-a -a
> a-a
> $ basename a-a -a
> a
>
> The following should address it and also have the
> benefit of short circuiting argument scanning.
>
> cheers,
> Pádraig.
>
> diff --git a/src/basename.c b/src/basename.c
> index 158ac7b..353ff08 100644
> --- a/src/basename.c
> +++ b/src/basename.c
> @@ -136,7 +136,7 @@ main (int argc, char **argv)
>
>   while (true)
>     {
> -      int c = getopt_long (argc, argv, "as:z", longopts, NULL);
> +      int c = getopt_long (argc, argv, "+as:z", longopts, NULL);
>
>       if (c == -1)
>         break;
> diff --git a/tests/misc/basename b/tests/misc/basename
> index 5415ca9..d0ab57b 100755
> --- a/tests/misc/basename
> +++ 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'}],
>      ['1', qw(f.s .s),     {OUT => 'f'}],
>      ['2', qw(fs s),       {OUT => 'f'}],
>      ['3', qw(fs fs),      {OUT => 'fs'}],
Thank you for fixing it for me. I will take to this more carefully now and
to the syntax problem you fixed too.

I was very busy this week, work travel with no real access to Internet,
so I didn't answer to these mails.

I will add the '-z' option to dirname too since if basename deserves it
dirname (with multiple argument) deserves it too.

Cheers,

Jérémy



reply via email to

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