[Linux-disciples] xargs questions
Adam Rosi-Kessel
adam at rosi-kessel.org
Thu Nov 11 16:59:14 EST 2004
Stephen R Laniel wrote:
> On Thu, Nov 11, 2004 at 08:18:29AM -0500, Adam Rosi-Kessel wrote:
>> I'm not sure what it's doing in the tail command above, but the point of
>> xargs is *not* to create commands that fit on the command line--the point
>> is to take STDIN and convert it to arguments to a command. It's
>> essential glue.
> If the command line could be arbitrarily long, why wouldn't
> we just use
> command1 `command2GeneratingInsanelyLongOutput`
> ?
First, it would often just be an annoying way to accomplish what you want.
You might have problems with nested backticks, quoting, etc.. One of
the great things about xargs is you don't need to worry about internal
escapes. (It also works well with the -0 option, where your arguments
are 'null' delimited, and then you don't have to worry about any odd
characters).
But more importantly command1 `command2` is just not equivalent to
command2 | xargs command1. The first turns a *pipe* into arguments, and
runs command1 repeatedly for each line of piped input. The backtick
example won't give the same results where the "insanely long output" is
several unique lines. Try it, you'll see.
You might also use xargs for odd things like, e.g., mkfifo. You could
have the output of a FIFO special file cat'd into xargs to be run as a
command. I suppose there's a way to do this with backticks in certain
circumstances, but xargs seems much more graceful.
--
Adam Rosi-Kessel
http://adam.rosi-kessel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20041111/ef3f4bcb/signature.pgp
More information about the Linux-disciples
mailing list