[Ilugc] XArgs

  • From: kapil@xxxxxxxxxxx (Kapil Hari Paranjape)
  • Date: Sat Jun 7 07:08:15 2008

Hello,

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.

Just to get the pipeline out of the way do the following
        ls / > /tmp/list
This produces a file with one file name on each line.

(Note below that the default command run by xargs is "echo")

Then run
        xarg -a /tmp/list
this produces the entire list on one line (which will be wrapped
around if your terminal is set to wrap mode).

On the other hand 
        xarg -a /tmp/list -i \{\}
produces a copy of /tmp/list

Kapil.
--

Other related posts: