xref: /netbsd-src/usr.bin/apply/apply.1 (revision 8abecf66a79e02a39563d7aeb1bca985b33e8249)
1*8abecf66Swiz.\"	$NetBSD: apply.1,v 1.15 2016/03/14 09:53:37 wiz Exp $
2f0dbf5d4Sglass.\"
3581df8a2Sglass.\" Copyright (c) 1983, 1990, 1993
4581df8a2Sglass.\"	The Regents of the University of California.  All rights reserved.
5581df8a2Sglass.\"
6581df8a2Sglass.\" Redistribution and use in source and binary forms, with or without
7581df8a2Sglass.\" modification, are permitted provided that the following conditions
8581df8a2Sglass.\" are met:
9581df8a2Sglass.\" 1. Redistributions of source code must retain the above copyright
10581df8a2Sglass.\"    notice, this list of conditions and the following disclaimer.
11581df8a2Sglass.\" 2. Redistributions in binary form must reproduce the above copyright
12581df8a2Sglass.\"    notice, this list of conditions and the following disclaimer in the
13581df8a2Sglass.\"    documentation and/or other materials provided with the distribution.
1489aaa1bbSagc.\" 3. Neither the name of the University nor the names of its contributors
15581df8a2Sglass.\"    may be used to endorse or promote products derived from this software
16581df8a2Sglass.\"    without specific prior written permission.
17581df8a2Sglass.\"
18581df8a2Sglass.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19581df8a2Sglass.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20581df8a2Sglass.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21581df8a2Sglass.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22581df8a2Sglass.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23581df8a2Sglass.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24581df8a2Sglass.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25581df8a2Sglass.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26581df8a2Sglass.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27581df8a2Sglass.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28581df8a2Sglass.\" SUCH DAMAGE.
29581df8a2Sglass.\"
30f0dbf5d4Sglass.\"     @(#)apply.1	8.2 (Berkeley) 4/4/94
31581df8a2Sglass.\"
3284481ccbSdholland.Dd March 12, 2016
33581df8a2Sglass.Dt APPLY 1
349e44e9b5Sgarbled.Os
35581df8a2Sglass.Sh NAME
36581df8a2Sglass.Nm apply
3784481ccbSdholland.Nd apply a command to a list of arguments
38581df8a2Sglass.Sh SYNOPSIS
3910a4ee85Slukem.Nm
40581df8a2Sglass.Op Fl a Ns Ar c
41581df8a2Sglass.Op Fl Ns Ar #
4284481ccbSdholland.Ar command arguments ...
43581df8a2Sglass.Sh DESCRIPTION
4410a4ee85Slukem.Nm
4584481ccbSdhollanddivides its
4684481ccbSdholland.Ar arguments
4784481ccbSdhollandinto fixed-size groups and runs
48581df8a2Sglass.Ar command
4984481ccbSdhollandin turn on each group.
50581df8a2Sglass.Pp
5184481ccbSdhollandOn each execution of
5284481ccbSdholland.Ar command ,
5384481ccbSdhollandeach character sequence of the form
54581df8a2Sglass.Dq Li \&%d
55581df8a2Sglassin
56581df8a2Sglass.Ar command ,
57581df8a2Sglasswhere
5884481ccbSdholland.Ar d
5984481ccbSdhollandis a digit from 1 to 9, is replaced with the
6084481ccbSdholland.Ar d Ns \'th
6184481ccbSdhollandargument from the current argument group.
6284481ccbSdhollandThe argument group size is set to the largest such
6384481ccbSdholland.Ar d
6484481ccbSdhollandfound.
6584481ccbSdhollandAny given argument number can be used arbitrarily many times.
6684481ccbSdholland(Including zero.)
6784481ccbSdholland.Pp
6884481ccbSdhollandIf no explicit substitution sequences are found in
6984481ccbSdholland.Ar command ,
7084481ccbSdhollandthe current argument group is substituted after
7184481ccbSdholland.Ar command
7284481ccbSdhollanddelimited by spaces, and the argument group size defaults to 1 and can
7384481ccbSdhollandbe set with the
7484481ccbSdholland.Fl #
7584481ccbSdhollandoption.
7684481ccbSdholland.Pp
7784481ccbSdhollandIf the argument group size is set to 0, one argument from
7884481ccbSdholland.Ar arguments
7984481ccbSdhollandis taken for each execution of
8084481ccbSdholland.Ar command
8184481ccbSdhollandanyway, but is discarded and not substituted; thus,
8284481ccbSdholland.Ar command
8384481ccbSdhollandis run verbatim once for every argument.
84581df8a2Sglass.Pp
85581df8a2SglassThe options are as follows:
86581df8a2Sglass.Bl -tag -width "-ac"
87581df8a2Sglass.It Fl Ns Ar #
8884481ccbSdhollandSet the argument group size.
8984481ccbSdhollandIgnored if explicit substitutions are used.
90581df8a2Sglass.It Fl a Ns Ar c
9184481ccbSdhollandChange the magic substitution character from the default
92581df8a2Sglass.Dq Li %
9384481ccbSdhollandto
9484481ccbSdholland.Ar c .
95581df8a2Sglass.El
96797e4e51Swiz.Sh ENVIRONMENT
97581df8a2SglassThe following environment variable affects the execution of
98990562bfSwiz.Nm :
99581df8a2Sglass.Bl -tag -width SHELL
100581df8a2Sglass.It Ev SHELL
10184481ccbSdhollandPathname of the shell to use to execute
10284481ccbSdholland.Ar command .
103581df8a2SglassIf this variable is not defined, the Bourne shell is used.
104581df8a2Sglass.El
105797e4e51Swiz.Sh FILES
106797e4e51Swiz.Bl -tag -width /bin/sh -compact
107797e4e51Swiz.It Pa /bin/sh
10884481ccbSdhollandDefault shell.
109797e4e51Swiz.El
110581df8a2Sglass.Sh EXAMPLES
111581df8a2Sglass.Bl -tag -width apply -compact
112e76d2900Swiz.It Li "apply echo *"
11384481ccbSdhollandPrints the name of every file in the current directory.
11484481ccbSdholland.It Li "apply \-2 diff a1 b1 a2 b2 a3 b3"
11584481ccbSdhollandCompares the `a' files to the `b' files.
116581df8a2Sglass.It Li "apply \-0 who 1 2 3 4 5"
11784481ccbSdhollandRuns
118c46ab392Sfair.Xr who 1
11984481ccbSdholland5 times.
12084481ccbSdholland.It Li "apply \'ln %1 /home/joe/joe.%1\'" *
12184481ccbSdhollandHard-links all files in the current directory into the directory
12284481ccbSdholland.Pa /home/joe ,
123*8abecf66Swizwith their names prefixed with "joe.".
12484481ccbSdholland.It Li "apply \'cvs diff %1 > %1.diff'" *.c
12584481ccbSdhollandDiff all C sources in the current directory against the last
12684481ccbSdhollandchecked-in version and store each result in its own output file.
127581df8a2Sglass.El
128797e4e51Swiz.Sh HISTORY
129797e4e51SwizThe
130797e4e51Swiz.Nm
131797e4e51Swizcommand appeared in
132797e4e51Swiz.Bx 4.2 .
133797e4e51Swiz.Sh AUTHORS
134797e4e51Swiz.An Rob Pike
13584481ccbSdholland.Sh RESTRICTIONS
13684481ccbSdhollandThe complete command to be executed on each iteration is assembled as
13784481ccbSdhollanda string without additional quoting and then passed to a copy of the
13884481ccbSdhollandshell for parsing and execution.
13984481ccbSdhollandThus, commands or arguments that contain spaces or shell
14084481ccbSdhollandmetacharacters may behave in unexpected ways.
14184481ccbSdholland.Pp
14284481ccbSdhollandTo protect a shell metacharacter fully it must be quoted twice, once
14384481ccbSdhollandagainst the current shell and once against the subshell used for
14484481ccbSdhollandexecution.
14584481ccbSdhollandSimilarly, for a shell metacharacter to be interpreted by the subshell
14684481ccbSdhollandit must be quoted to protect it from the current shell.
14784481ccbSdhollandA simple rule of thumb is to enclose the entire
148581df8a2Sglass.Ar command
14984481ccbSdhollandin single quotes
15084481ccbSdholland.Pq ''
15184481ccbSdhollandso that the current shell does not interpret any of it.
1521bdc2bf3Sdholland.Sh BUGS
1531bdc2bf3SdhollandThere is no easy way to produce the literal string
1541bdc2bf3Sdholland.Dq %1
1551bdc2bf3Sdhollandin
1561bdc2bf3Sdholland.Ar command .
1571bdc2bf3Sdholland.Pp
1581bdc2bf3Sdholland.Nm
1591bdc2bf3Sdhollandunconditionally inserts "exec" at the beginning of each copy of
1601bdc2bf3Sdholland.Ar command
1611bdc2bf3Sdhollandso compound commands may not behave as intended.
162