1 .\" $NetBSD: wordexp.3,v 1.2 2006/04/24 20:27:34 jld Exp $
3 .\" Copyright (c) 2002 Tim J. Robbins
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/wordexp.3,v 1.6 2003/09/08 19:57:14 ru Exp $
34 .Nd "perform shell-style word expansions"
40 .Fn wordexp "const char * restrict words" "wordexp_t * restrict pwordexp" "int flags"
42 .Fn wordfree "wordexp_t *pwordexp"
46 function performs shell-style word expansion on
48 and places the list of expanded words into the structure pointed to by
53 argument is the bitwise inclusive OR of any of the following constants:
54 .Bl -tag -width ".Dv WRDE_SHOWERR"
56 Append the words to those generated by a previous call to
61 pointers as are specified by the
65 are added to the front of
68 Disallow command substitution in
76 argument was passed to a previous successful call to
78 but has not been passed to
80 The implementation may reuse the space allocated to it.
82 Do not redirect shell error messages to
85 Report error on an attempt to expand an undefined shell variable.
90 includes the following members:
91 .Bd -literal -offset indent
99 member is the count of generated words.
103 member points to a list of pointers to expanded words.
107 member is the number of slots to reserve at the beginning of the
111 It is the caller's responsibility to allocate the storage pointed to by
115 function allocates other space as needed, including memory
122 function frees the memory allocated by
124 .Sh IMPLEMENTATION NOTES
127 function is implemented as a wrapper around the undocumented
129 shell built-in command.
133 function returns zero if successful, otherwise it returns one of the following
135 .Bl -tag -width ".Dv WRDE_NOSPACE"
139 argument contains one of the following unquoted characters:
151 An attempt was made to expand an undefined shell variable and
156 An attempt was made to use command substitution and
161 Not enough memory to store the result.
163 Shell syntax error in
166 An internal error occured and
168 is set to indicate the error.
173 function returns no value.
175 .Bl -tag -width ".Ev IFS"
180 Invoke the editor on all
182 files in the current directory
185 (error checking omitted):
186 .Bd -literal -offset indent
189 wordexp("${EDITOR:-vi} *.c /etc/motd", \*[Am]we, 0);
190 execvp(we-\*[Gt]we_wordv[0], we-\*[Gt]we_wordv);
193 Diagnostic messages from the shell are written to the standard error output
211 Their first release was in
217 Do not pass untrusted user data to
219 regardless of whether the
224 function attempts to detect input that would cause commands to be
225 executed before passing it to the shell
226 but it does not use the same parser so it may be fooled.