O'Reilly logo

Mac OS X Tiger in a Nutshell by Jason McIntosh, Chuck Toporek, Chris Stone, Andy Lester

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

-a character

Use character instead of %.

- number

Instead of pairing arguments one at a time with command, use them number at a time with command. If number is 0, none of the arguments will be used with command, but command will still run once for each item listed in arguments. If command contains % n, number is ignored.

Examples

Ping three different hosts, sending three packets to each:

$ apply 'ping -c3' host1.com host2.com host3.com

Ping three different hosts, sending a different number of packets to each:

$ apply -2 'ping -c' 3 host1.com 4 host2.com 5 host3.com

Ping three different hosts, and write output to file pinglog:

$ apply 'ping -c3 %1 >> pinglog' host1.com  host2.com ,
                     
                     host3.com

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required