xref: /netbsd/usr.bin/xargs/xargs.1 (revision bf9ec67e)
1.\"	$NetBSD: xargs.1,v 1.14 2002/01/28 13:49:49 wiz Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" John B. Roll Jr. and the Institute of Electrical and Electronics
8.\" Engineers, Inc.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.\"	@(#)xargs.1	8.1 (Berkeley) 6/6/93
39.\"
40.Dd December 21, 1999
41.Dt XARGS 1
42.Os
43.Sh NAME
44.Nm xargs
45.Nd "construct argument list(s) and execute utility"
46.Sh SYNOPSIS
47.Nm
48.Op Fl 0
49.Op Fl p
50.Op Fl t
51.Oo Op Fl x
52.Fl n Ar number
53.Oc
54.Op Fl s Ar size
55.Op Ar utility Op Ar arguments ...
56.Sh DESCRIPTION
57The
58.Nm
59utility reads space, tab, newline and end-of-file delimited arguments
60from the standard input and executes the specified
61.Ar utility
62with them as
63arguments.
64.Pp
65The utility and any arguments specified on the command line are given
66to the
67.Ar utility
68upon each invocation, followed by some number of the arguments read
69from standard input.
70The
71.Ar utility
72is repeatedly executed until standard input is exhausted.
73.Pp
74Spaces, tabs and newlines may be embedded in arguments using single
75(``\ '\ '')
76or double (``"'') quotes or backslashes (``\e'').
77Single quotes escape all non-single quote characters, excluding newlines,
78up to the matching single quote.
79Double quotes escape all non-double quote characters, excluding newlines,
80up to the matching double quote.
81Any single character, including newlines, may be escaped by a backslash.
82.Pp
83The options are as follows:
84.Bl -tag -width Fl
85.It Fl 0
86Use NUL
87(``\e0'')
88instead of whitespace as the argument separator.
89This can be used in conjuction with the
90.Fl print0
91option of
92.Xr find 1 .
93.It Fl n Ar number
94Set the maximum number of arguments taken from standard input for each
95invocation of the utility.
96An invocation of
97.Ar utility
98will use less than
99.Ar number
100standard input arguments if the number of bytes accumulated (see the
101.Fl s
102option) exceeds the specified
103.Ar size
104or there are fewer than
105.Ar number
106arguments remaining for the last invocation of
107.Ar utility .
108The current default value for
109.Ar number
110is 5000.
111.It Fl p
112Prompt mode: immediately before each command execution the user is prompted
113whether to execute the command instance.  If an affirmative response is read
114from
115.Pa /dev/tty
116the command will be executed; otherwise this particular invocation will be
117skipped.
118This option implies the
119.Fl t
120option.
121.It Fl s Ar size
122Set the maximum number of bytes for the command line length provided to
123.Ar utility .
124The sum of the length of the utility name and the arguments passed to
125.Ar utility
126(including
127.Dv NULL
128terminators) will be less than or equal to this number.
129The current default value for
130.Ar size
131is
132.Dv ARG_MAX
133- 4096.
134.It Fl t
135Echo the command to be executed to standard error immediately before it
136is executed.
137.It Fl x
138Force
139.Nm
140to terminate immediately if a command line containing
141.Ar number
142arguments will not fit in the specified (or default) command line length.
143.El
144.Pp
145If no
146.Ar utility
147is specified,
148.Xr echo 1
149is used.
150.Pp
151Undefined behavior may occur if
152.Ar utility
153reads from the standard input.
154.Pp
155The
156.Nm
157utility exits immediately (without processing any further input) if a
158command line cannot be assembled,
159.Ar utility
160cannot be invoked, an invocation of the utility is terminated by a signal
161or an invocation of the utility exits with a value of 255.
162.Sh EXIT STATUS
163.Nm
164exits with one of the following values:
165.Bl -tag -width Ds -compact
166.It 0
167All invocations of
168.Ar utility
169returned a zero exit status.
170.It 123
171One or more invocations of
172.Ar utility
173returned a nonzero exit status.
174.It 124
175The
176.Ar utility
177exited with a 255 exit status.
178.It 125
179The
180.Ar utility
181was killed or stopped by a signal.
182.It 126
183The
184.Ar utility
185was found but could not be invoked.
186.It 127
187The
188.Ar utility
189could not be found.
190.It 1
191Some other error occurred.
192.El
193.Sh FILES
194.Bl -tag -width /dev/tty -compact
195.It Pa /dev/tty
196used to read responses in prompt mode
197.El
198.Sh SEE ALSO
199.Xr echo 1 ,
200.Xr find 1
201.Sh STANDARDS
202The
203.Nm
204utility is expected to be
205.St -p1003.2
206compliant.
207.Sh HISTORY
208The
209.Nm xargs
210command appeared in PWB Unix 1.0.
211It made its first BSD appearance in the 4.3 Reno release.
212.Pp
213The meaning of 123, 124, and 125 exit values and the
214.Fl 0
215option were taken from GNU xargs.
216