GNU bug report logs - #14023
dirname/basename unexpected results when run by xargs -I

Previous Next

Package: coreutils;

Reported by: Juho-Pekka Kuitunen <artanicus <at> mythmardyl.org>

Date: Fri, 22 Mar 2013 00:37:04 UTC

Severity: normal

Tags: moreinfo

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juho-Pekka Kuitunen <artanicus <at> mythmardyl.org>
To: Bob Proulx <bob <at> proulx.com>
Cc: 14023 <at> debbugs.gnu.org
Subject: bug#14023: dirname/basename unexpected results when run by xargs -I
Date: Fri, 22 Mar 2013 04:52:25 +0200
On Fri, Mar 22, 2013 at 3:05 AM, Bob Proulx <bob <at> proulx.com> wrote:
> Juho-Pekka Kuitunen wrote:
>> Reproduce example;
>> $ echo "testdir/testfile" | xargs -I '{}' echo '{}', dir: $(echo dirname '{}') = $(dirname '{}')
>
> Thank you for the report and the very nice test case.  It made
> debugging this problem so very much simpler.
>
>> Expected output;
>> testdir/testfile, dir: dirname testdir/testfile = testdir
>>
>> Actual output;
>> testdir/testfile, dir: dirname testdir/testfile = .
>
> Ah...  But you have missed a critical point!  :-)  The $(...) is
> expanded by the current shell and not by the xargs.  Use echo to see
> what you are asking.
>
>   $ echo xargs -I '{}' echo '{}', dir: $(echo dirname '{}') = $(dirname '{}')
>   xargs -I {} echo {}, dir: dirname {} = .
>
>> This behavior seems to be limited to the xargs -I replace-str usage
>> pattern, any other way I can think of running dirname works fine.
>
> The problem is the $(...) which is running the dirname during the
> earlier shell command line parsing pass and passing the result off to
> the xargs command.

So if I understand correctly, subshell replacements gets executed
before xargs fills in the replacements? I tried to rule out this
wonkyness with the "$(echo '{}')" bit and it seemed to work in the
correct order. The echo should produce an empty string if the subshell
was evaluated too soon?

>
>> Basename has similarly wonky behavior, it prints the full string
>> instead of doing any stripping.
>
> Also using $(...)?  :-)
>
>> Not sure if there's a bug involved (or if it's on the findutils or
>> coreutils side). Could also just be something silly I'm overlooking.
>> I've tested this with findutils 4.4.2 and coreutils 8.5 & 8.13 with
>> identical results.
>
> So...  Not a bug.  Agreed?  (I am having a good chuckle.  I hope you
> will too.)  We will close the bug then.
>

Very much possibly not a bug but I'm not 100% convinced yet. I've been
chuckling at this all evening, love a good brain teaser even if it
turns out to be something I overlooked instead of a bug. :-)

> Bob



--
Juho-Pekka Kuitunen




This bug report was last modified 12 years and 64 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.