[Ilugc] XArgs

  • From: masatran@xxxxxxxxxxxxxxxxxxx (Masatran, R. Deepak)
  • Date: Sat Jun 7 14:57:57 2008

* Kapil Hari Paranjape <kapil@xxxxxxxxxxx> 2008-06-07

On Sat, 07 Jun 2008, Masatran, R. Deepak wrote:
Aren't

    xargs foo

and

    xargs -i foo {}

supposed to be identical? Why do they act different?

Because they are not identical!

The first takes the white-space separated words from standard input
and assigns them as ARG1, ARG2, ....
and runs foo with _all_ these arguments.

The second takes _each_ white-space separated word from standard
input and runs foo with ARG1 set to that word.

Eureka! I scanned the man page again and found a switch "-l" which forces
each input argument to be processed separately. Therefore, it is

    xargs -l foo

that is equivalent to

    xargs -i foo {}

Now onwards, I will always use "-l" with XArgs. Isn't XArgs the greatest
command on Unix!!

-- 
Masatran, R. Deepak <http://research.iiit.ac.in/~masatran/>


Other related posts: