2 .\" Copyright (c) 2002 Tim J. Robbins
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" $FreeBSD: src/lib/libc/gen/wordexp.3,v 1.9 2006/04/18 21:37:24 ceri Exp $
27 .\" $DragonFly: src/lib/libc/gen/wordexp.3,v 1.1 2008/10/06 21:01:37 swildner Exp $
34 .Nd "perform shell-style word expansions"
40 .Fn wordexp "const char * restrict words" "wordexp_t * restrict we" "int flags"
42 .Fn wordfree "wordexp_t *we"
46 function performs shell-style word expansion on
48 and places the list of words into the
52 and the number of words into
57 argument is the bitwise inclusive OR of any of the following constants:
58 .Bl -tag -width ".Dv WRDE_SHOWERR"
60 Append the words to those generated by a previous call to
65 pointers as are specified by the
69 are added to the front of
72 Disallow command substitution in
80 argument was passed to a previous successful call to
82 but has not been passed to
84 The implementation may reuse the space allocated to it.
86 Do not redirect shell error messages to
89 Report error on an attempt to expand an undefined shell variable.
94 structure is defined in
97 .Bd -literal -offset indent
99 size_t we_wordc; /* count of words matched */
100 char **we_wordv; /* pointer to list of words */
101 size_t we_offs; /* slots to reserve in we_wordv */
107 function frees the memory allocated by
109 .Sh IMPLEMENTATION NOTES
112 function is implemented as a wrapper around the undocumented
114 shell built-in command.
118 function returns zero if successful, otherwise it returns one of the following
120 .Bl -tag -width ".Dv WRDE_NOSPACE"
124 argument contains one of the following unquoted characters:
136 An attempt was made to expand an undefined shell variable and
141 An attempt was made to use command substitution and
146 Not enough memory to store the result.
148 Shell syntax error in
154 function returns no value.
156 .Bl -tag -width ".Ev IFS"
161 Invoke the editor on all
163 files in the current directory
166 (error checking omitted):
167 .Bd -literal -offset indent
170 wordexp("${EDITOR:-vi} *.c /etc/motd", &we, 0);
171 execvp(we.we_wordv[0], we.we_wordv);
174 Diagnostic messages from the shell are written to the standard error output
193 Do not pass untrusted user data to
195 regardless of whether the
200 function attempts to detect input that would cause commands to be
201 executed before passing it to the shell
202 but it does not use the same parser so it may be fooled.
206 implementation does not recognize multibyte characters, since the
207 shell (which it invokes to perform expansions) does not.