in reply to Receiving Standard Input/Piped

ls | prog will be treated as an input to the prog and not as a command line arg

for example do ls | cat you will get ls back (minus the color etc. if you had them turned on)

you need ls | xargs cat or ls | xargs prog

Replies are listed 'Best First'.
Re^2: Receiving Standard Input/Piped
by thekestrel (Friar) on Sep 08, 2005 at 16:06 UTC
    of course... =P
    So xargs just opens up standard input, reads data, reads a file per line as default and calls an instance of the following program with a command line argument of one of the files for each file.
    I was trying to think of any other programs that do this in one go and can process standard input as arguments also (inherant xargs), but couldn't come up with any.
    The closest thing I could think of that I use...
    find -name "*.h" -exec grep "search word" {} \; -print
    looks like its just the same thing, once find has all the files, call and instance of grep with a single argument.
    Anyways thanks for your help, thats what I needed =).

    Regards Paul.
      So xargs just opens up standard input, reads data, reads a file per line as default and calls an instance of the following program with a command line argument of one of the files for each file.

      Actually xargs can-call/calls the program with multiple args. You can also specify the number of args using -n switch

      people prefer xargs because it avoids the Argument list too long problem. Also the -exec is not as efficient as xargs because it calls the prog each time it finds a file while xargs knows how big is OK and calls it accordingly! i.e. fewer calls to the prog

      cheers

      SK