1.\" Copyright (c) 1983, 1990, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd January 28, 2022 29.Dt APPLY 1 30.Os 31.Sh NAME 32.Nm apply 33.Nd apply a command to a set of arguments 34.Sh SYNOPSIS 35.Nm 36.Op Fl a Ar c 37.Op Fl d 38.Op Cm - Ns Ar # 39.Ar command argument ... 40.Sh DESCRIPTION 41The 42.Nm 43utility runs the named 44.Ar command 45on each 46argument 47.Ar argument 48in turn. 49.Pp 50Character sequences of the form 51.Dq Li \&%d 52in 53.Ar command , 54where 55.Sq Li d 56is a digit from 1 to 9, are replaced by the 57.Li d Ns \'th 58following unused 59.Ar argument . 60In this case, the largest digit number of arguments are discarded for 61each execution of 62.Ar command . 63.Pp 64The options are as follows: 65.Bl -tag -width indent 66.It Cm - Ns Ar # 67Normally arguments are taken singly; the optional number 68.Ar # 69specifies the number of arguments to be passed to 70.Ar command . 71If the number is zero, 72.Ar command 73is run, without arguments, once for each 74.Ar argument . 75.Pp 76If any sequences of 77.Dq Li \&%d 78occur in 79.Ar command , 80the 81.Fl # 82option is ignored. 83.It Fl a Ar c 84The use of the character 85.Sq Li % 86as a magic character may be changed with the 87.Fl a 88option. 89.It Fl d 90Display the commands that would have been executed, but do not actually 91execute them. 92.El 93.Sh ENVIRONMENT 94The following environment variable affects the execution of 95.Nm : 96.Bl -tag -width SHELL 97.It Ev SHELL 98Pathname of shell to use. 99If this variable is not defined, the Bourne shell is used. 100.El 101.Sh FILES 102.Bl -tag -width /bin/sh -compact 103.It Pa /bin/sh 104default shell 105.El 106.Sh EXAMPLES 107.Bl -tag -width apply -compact 108.It Li "apply echo *" 109is similar to 110.Xr ls 1 ; 111.It Li "apply \-2 cmp a1 b1 a2 b2 a3 b3" 112compares the `a' files to the `b' files; 113.It Li "apply \-0 who 1 2 3 4 5" 114runs 115.Xr who 1 1165 times; and 117.It Li "apply \'ln %1 /usr/joe\'" * 118links all files in the current directory to the directory 119.Pa /usr/joe . 120.El 121.Sh HISTORY 122The 123.Nm 124command appeared in 125.Bx 4.2 . 126.Sh AUTHORS 127.An Rob Pike 128.Sh BUGS 129Shell metacharacters in 130.Ar command 131may have bizarre effects; it is best to enclose complicated 132commands in single quotes 133.Pq '' . 134.Pp 135The 136.Nm 137utility does not recognize multibyte characters. 138