[Top][All Lists]

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

[bugs #8211] using -i breaks xargs

From: James Youngman
Subject: [bugs #8211] using -i breaks xargs
Date: Fri, 19 Nov 2004 18:35:54 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041007 Debian/1.7.3-5

This mail is an automated notification from the bugs tracker
 of the project: findutils.

[bugs #8211] Latest Modifications:

Changes by: 
                James Youngman <address@hidden>
                Fri 11/19/04 at 23:19 (GMT)

            What     | Removed                   | Added
         Assigned to | None                      | jay
       Fixed Release | None                      | 4.2.5

[bugs #8211] Full Item Snapshot:

URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=8211>
Project: findutils
Submitted by: 0
On: Fri 03/19/04 at 15:27

Category:  xargs
Severity:  5 - Average
Item Group:  None
Resolution:  Fixed
Privacy:  Public
Assigned to:  jay
Originator Name:  
Originator Email:  
Status:  Open
Release:  4.2.4
Fixed Release:  4.2.5

Summary:  using -i breaks xargs

Original Submission:  Using -i to xargs makes it stop being useful:

$ echo * | xargs echo foo | wc -l
$ echo * | xargs -i echo {} foo | wc -l
xargs: argument line too long

I understand that the point of xargs is splitting one long command in multiple 
commands to avoid errors.  If -i is specified, it no longer does that, so using 
xargs has no advantage over executing the long command directly (and just adds 
some overhead).

I guess this is the same bug that was reported to Debian's bug tracking system 
in Jan 1999 (see <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=31858>), 
though the report there makes it seem like the bug is not as bad as it actually 

Follow-up Comments

Date: Mon 11/08/04 at 21:35         By: James Youngman <jay>
I have made the suggested change to the documentation (this will be included in 
findutils-4.2.5).   The patch is attached.

Date: Sun 11/07/04 at 11:49         By: Andreas Metzler <ametzler>
aarghh, typo.
replace "only split on blanks:" with "only split on newline:"

Date: Sun 11/07/04 at 11:47         By: Andreas Metzler <ametzler>
Jay writes:
> I believe that this is the behaviour of the "-i" option that > shold be 
> expected. Certainly it seems consistent with the
> behaviour of xargs on Solaris.

I think you are right, POSIX/Susv3 (XSI extension) seems to support your 
interpretation that -i should change xargs from splitting at <space> to only 
split on blanks:

-I  replstr
    [XSI] [Option Start] Insert mode: utility is executed for each line from 
standard input, taking the entire line as a single argument,[...]

And I'd expect -I and -i to be the same.

More supporting data:
address@hidden>uname -a
AIX login 2 5 00404A0A4C00
address@hidden>echo a b | xargs -I'{}' `pwd`/a.out X {} Y
Arg 0: [/u/user5/a9203835/a.out]
Arg 1: [X]
Arg 2: [a b]
Arg 3: [Y]
address@hidden>echo a b | xargs  `pwd`/a.out X {} Y
Arg 0: [/u/user5/a9203835/a.out]
Arg 1: [X]
Arg 2: [{}]
Arg 3: [Y]
Arg 4: [a]
Arg 5: [b]
address@hidden>printf 'anbn' | xargs -I'{}' `pwd`/a.out X {} Y
Arg 0: [/u/user5/a9203835/a.out]
Arg 1: [X]
Arg 2: [a]
Arg 3: [Y]
Arg 0: [/u/user5/a9203835/a.out]
Arg 1: [X]
Arg 2: [b]
Arg 3: [Y]

AIX's finds provides both -i and -I and both behave identically.

I suggest to update GNU findutil's documentation to _clearly_ note that '-i' 
stop xargs from splitting at blanks and makes it pass _the_ complete line to 
the command and /after/ that close this bug.

Date: Mon 05/03/04 at 10:06         By: James Youngman <jay>
I believe that this is the behaviour of the "-i" option that shold be expected. 
 Certainly it seems consistent with the behaviour of xargs on Solaris.

Date: Tue 03/23/04 at 05:20         By: 0 <None>
I did some further tests with the following program (C code):

main ( int argc, char **argv ) { int i; for (i = 0; i < argc; i ++) { 
printf("Arg %d: [%s]n", i, argv[i]); } }

It shows that -i changes the way xargs invocates its command:

$ echo 0 1 | xargs ./test
Arg 0: [./main]
Arg 1: [0]
Arg 2: [1]
$ echo 0 1 | xargs -i ./test {}
Arg 0: [./main]
Arg 1: [0 1]

strace also confirms this.  With -i xargs calls
execve("./main", ["./main", "0 1"], [/* 25 vars */])
whereas normally it calls
execve("./main", ["./main", "0", "1"], [/* 25 vars */]).

Very frustrating. :(

Date: Tue 03/23/04 at 05:11         By: 0 <None>
Arg, my "nice workaround" does not really work.  It triggers some other bug in 
xargs' -i.

The following commands ilustrate the bug:

$ touch 0 1 ; echo * | xargs -i rm {}
rm: cannot remove `0 1': No such file or directory

Needless to say, ``xargs rm'' just works.  I am just using the -i parameter in 
this example to show what's broken.  I don't see any reason why the above 
command should fail.

There are some circunstances when the user really needs the -i option (such as 
to use my workaround for the first bug) and then this second bug bites him.

Is -i really as broken as it seems (and has it been that broken since 1999, 
when it seems its first bugs were reported) or am I just missing something?

Date: Tue 03/23/04 at 04:27         By: 0 <None>
I found out a nice workaround:
$ echo * | xargs | xargs -i echo {} foo | wc -l 

Still, the bug should be fixed, really fixed.

CC List

CC Address                          | Comment
31858 --AT-- bugs --DOT-- debian --DOT-- org | similar report in Debian BTS

File Attachments

Date: Mon 11/08/04 at 21:35  Name: xargs-i-doc.patch  Size: 2.39KB   By: jay


For detailed info, follow this link:

  Message sent via/by Savannah

reply via email to

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