Name
apply
Synopsis
apply [options]command arguments
Allows you to run a given command multiple times, each time with a
different argument. By default, apply pairs and
runs command followed by each argument
listed in arguments. To place the argument
elsewhere in command, mark that location
in command with
%
n, where
n is the nth
unused item listed in arguments (see
examples).
Options
-
-acharacter Use
characterinstead of%.-
-number Instead of pairing arguments one at a time with
command, use themnumberat a time withcommand. Ifnumberis 0, none of the arguments will be used withcommand, butcommandwill still run once for each item listed inarguments. Ifcommandcontains%n,numberis ignored.
Examples
Ping three different hosts, sending three packets to each:
$ apply 'ping -c3' host1.com host2.com host3.comPing three different hosts, sending a different number of packets to each:
$ apply -2 'ping -c' 3 host1.com 4 host2.com 5 host3.comPing three different hosts, and write output to file
pinglog:
$apply 'ping -c3 %1 >> pinglog' host1.com host2. com⊘host3.com
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access