[BusyBox] [patch] Why busybox xargs is broken.

Rob Landley rob at landley.net
Thu Oct 2 11:33:09 UTC 2003

$ echo -e "one\ntwo\nthree\nfour" | xargs echo
one two three four
$ echo -e "one\ntwo\nthree\nfour" | xargs -n 2 echo
one two
three four
$ echo -e "one\ntwo\nthree\nfour" | ./busybox xargs echo

This is what was screwing up grep for me earlier.

So I hit it repeatedly with a stick until a patch came out.  I added the -n 
option, factored out all the command line option handling under a new 
#define, which is in Config.in (so those people who really want to save 100 
bytes can disable the command line options to xargs entirely, not that we're 
posix compliant with it enabled)...

And more or less rewrote about 2/3 of it because it was an unitellgible MESS.
(And I do not like libbb/getopt_ulflags.c.  Trying to figure out how it works 
is not fun.  The first four comment lines are:

  You can set bb_opt_complementaly as string with one or more
  complementaly or incongruously options.
  If sequential founded option haved from this string
  then your incongruously pairs unsets and complementaly make add sets.

That was the point at which I gave up and used "getopt" out of the library, 
until I realised it was reorganizing command line options (bad if the options 
are in the command xargs is execing and not options to xargs), so I fell back 
to a for loop.  (It's not rocket surgery...)

On a side note, while debugging this, I cleaned up something in busybox.c too, 
but that's a different patch.  (Also attached.)

Note: the -p option doesn't work, because when you're using xargs you're 
piping stuff to stdin more or less by definition, so reading from stdin to 
get a y typed at you is kind of pointless, no?  We need to find the 
controlling tty and read from that.  I'm not dealing with that right now.

Here there be a patch.  (And dragons.)  It worked for me, your mileage may 


As Pete Abrams says, "And that's it, I'm going back to bed."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: busybox.patch
Type: text/x-diff
Size: 788 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20031002/ae6f34ed/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xargs.patch
Type: text/x-diff
Size: 6707 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20031002/ae6f34ed/attachment-0001.bin 

More information about the busybox mailing list