[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 1


apply Command

Purpose

Applies a command to a set of parameters.

Syntax

apply-aCharacter ] [  -Number ] CommandString Parameter ...

Description

The apply command runs a command string specified by the CommandString parameter on each specified value of the Parameter parameter in turn. Normally, Parameter values are chosen individually; the optional -Number flag specifies the number of Parameter values to be passed to the specified command string. If the value of the Number variable is 0, the command string is run without parameters once for each Parameter value.

If you include character sequences of the form %n (where n is a digit from 1 to 9) in CommandString, they are replaced by the nth unused Parameter value following the CommandString parameter when the command string is executed. If any such sequences occur, the apply command ignores the -Number flag, and the number of parameters passed to CommandString is the maximum value of n in the CommandString parameter.

You can specify a character other than % (percent sign) to designate parameter substitution character strings with the -a flag; for example, -a@ would indicate that the sequences @1 and @2 would be replaced by the first and second unused parameters following the CommandString parameter.

Notes:
  1. Because pattern-matching characters in CommandString may have undesirable effects, it is recommended that complicated commands be enclosed in ' ' (single quotation marks).
  2. You cannot pass a literal % (percent sign) followed immediately by any number without using the -a flag.

Flags


-aCharacter Specifies a character (other than %) to designate parameter substitution strings.
-Number Specifies the number of parameters to be passed to CommandString each time it is run.

Examples

  1. To obtain results similar to those of the ls command, enter:

    apply echo *
    
  2. To compare the file named a1 to the file named b1, and the file named a2 to the file named b2, enter:

    apply -2 cmp a1 b1 a2 b2
    
  3. To run the who command five times, enter:

    apply -0 who 1 2 3 4 5
    
  4. To link all files in the current directory to the directory /usr/joe, enter:

    apply 'ln %1 /usr/joe' *
    

Related Information

The xargs command.

Input and Output Redirection Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.

Shells Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]