APPLY(1) | General Commands Manual | APPLY(1) |
apply
— apply a
command to a list of arguments
apply |
[-a c]
[- #] command
arguments ... |
apply
divides its
arguments into fixed-size groups and runs
command in turn on each group.
On each execution of command, each character
sequence of the form “%d
” in
command, where d is a digit from
1 to 9, is replaced with the d´th argument from
the current argument group. The argument group size is set to the largest
such d found. Any given argument number can be used
arbitrarily many times. (Including zero.)
If no explicit substitution sequences are found in
command, the current argument group is substituted
after command delimited by spaces, and the argument
group size defaults to 1 and can be set with the -#
option.
If the argument group size is set to 0, one argument from arguments is taken for each execution of command anyway, but is discarded and not substituted; thus, command is run verbatim once for every argument.
The options are as follows:
-
#-a
c%
” to c.The following environment variable affects the execution of
apply
:
SHELL
apply echo
*
apply
-2 diff a1 b1 a2 b2 a3 b3
apply
-0 who 1 2 3 4 5
apply
´ln %1 /home/joe/joe.%1´ *
apply
´cvs diff %1 > %1.diff' *.c
The apply
command appeared in
4.2BSD.
Rob Pike
The complete command to be executed on each iteration is assembled as a string without additional quoting and then passed to a copy of the shell for parsing and execution. Thus, commands or arguments that contain spaces or shell metacharacters may behave in unexpected ways.
To protect a shell metacharacter fully it must be quoted twice, once against the current shell and once against the subshell used for execution. Similarly, for a shell metacharacter to be interpreted by the subshell it must be quoted to protect it from the current shell. A simple rule of thumb is to enclose the entire command in single quotes ('') so that the current shell does not interpret any of it.
There is no easy way to produce the literal string “%1” in command.
apply
unconditionally inserts
"exec" at the beginning of each copy of
command so compound commands may not behave as
intended.
March 12, 2016 | NetBSD 10.99 |