Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)

xargs(1) OSS Shell and Utilities Reference Manual
main.c readit.c
gettoken.c
putobj.c
Then xargs constructs and runs the command:
ls -l main.c readit.c gettoken.c putobj.c
Each shell command line can be up to LINE_MAX bytes long. If cles contains more
lenames than t on a single line, then xargs runs the ls command with the lenames
that t. It then constructs and runs another ls command using the remaining lenames.
Depending on the names listed in cles, the commands might look like the following:
ls -l main.c readit.c gettoken.c...
ls -l getisx.c getprp.c getpid.c...
ls -l tadd.c tmult.c tdiv.c...
2. To construct commands that contain a certain number of lenames, use a command line
similar to the following:
xargs -t -n 2 diff <<end
starting chap1 concepts chap2 writing
chap3
end
This constructs and runs diff commands that contain two lenames each (-n 2):
diff starting chap1
diff concepts chap2
diff writing chap3
The -t ag tells xargs to display each command before running it so that you can see
what is happening. The <<end and end arguments dene a Here Document, which uses
the text entered before the end line as standard input for the xargs command. (For more
details, see the section Inline Input (Here) Documents in the sh reference page.)
3. To insert lenames into the middle of commands, use a command line similar to the fol-
lowing:
ls | xargs -t -r mv {} {}.old
This renames all les in the current directory by adding .old to the end of each name.
The -r tells xargs to insert each line of the ls directory listing where {}(braces) appear.
(You might need to precede the braces with shell escape characters, depending on what
shell you are using.)
If the current directory contains the les chap1, chap2, and chap3, then this constructs
the following commands:
mv chap1 chap1.old
mv chap2 chap2.old
mv chap3 chap3.old
4. To run a command on les that you select individually, use a command line similar to the
following:
ls | xargs -p -n 1 ar r lib.a
This allows you to select les to add to the library lib.a. The -p ag tells xargs to
display each ar command it constructs and ask if you want to run it. Press y, or the
1034 Hewlett-Packard Company 527188-007