1faea1495STim J. Robbins.\" 2faea1495STim J. Robbins.\" Copyright (c) 2002 Tim J. Robbins 3faea1495STim J. Robbins.\" All rights reserved. 4faea1495STim J. Robbins.\" 5faea1495STim J. Robbins.\" Redistribution and use in source and binary forms, with or without 6faea1495STim J. Robbins.\" modification, are permitted provided that the following conditions 7faea1495STim J. Robbins.\" are met: 8faea1495STim J. Robbins.\" 1. Redistributions of source code must retain the above copyright 9faea1495STim J. Robbins.\" notice, this list of conditions and the following disclaimer. 10faea1495STim J. Robbins.\" 2. Redistributions in binary form must reproduce the above copyright 11faea1495STim J. Robbins.\" notice, this list of conditions and the following disclaimer in the 12faea1495STim J. Robbins.\" documentation and/or other materials provided with the distribution. 13faea1495STim J. Robbins.\" 14faea1495STim J. Robbins.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15faea1495STim J. Robbins.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16faea1495STim J. Robbins.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17faea1495STim J. Robbins.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18faea1495STim J. Robbins.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19faea1495STim J. Robbins.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20faea1495STim J. Robbins.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21faea1495STim J. Robbins.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22faea1495STim J. Robbins.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23faea1495STim J. Robbins.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24faea1495STim J. Robbins.\" SUCH DAMAGE. 25faea1495STim J. Robbins.\" 26faea1495STim J. Robbins.\" $FreeBSD$ 27faea1495STim J. Robbins.\" 28f825dd29STim J. Robbins.Dd July 29, 2004 29faea1495STim J. Robbins.Dt WORDEXP 3 30faea1495STim J. Robbins.Os 31faea1495STim J. Robbins.Sh NAME 32faea1495STim J. Robbins.Nm wordexp 33faea1495STim J. Robbins.Nd "perform shell-style word expansions" 34faea1495STim J. Robbins.Sh LIBRARY 35faea1495STim J. Robbins.Lb libc 36faea1495STim J. Robbins.Sh SYNOPSIS 37faea1495STim J. Robbins.In wordexp.h 38faea1495STim J. Robbins.Ft int 390e35e492SRuslan Ermilov.Fn wordexp "const char * restrict words" "wordexp_t * restrict we" "int flags" 40be074a2dSTim J. Robbins.Ft void 410e35e492SRuslan Ermilov.Fn wordfree "wordexp_t *we" 42faea1495STim J. Robbins.Sh DESCRIPTION 43faea1495STim J. RobbinsThe 44faea1495STim J. Robbins.Fn wordexp 45faea1495STim J. Robbinsfunction performs shell-style word expansion on 46faea1495STim J. Robbins.Fa words 47faea1495STim J. Robbinsand places the list of words into the 48faea1495STim J. Robbins.Va we_wordv 49faea1495STim J. Robbinsmember of 500e35e492SRuslan Ermilov.Fa we , 51faea1495STim J. Robbinsand the number of words into 52faea1495STim J. Robbins.Va we_wordc . 53faea1495STim J. Robbins.Pp 54faea1495STim J. RobbinsThe 550e35e492SRuslan Ermilov.Fa flags 56faea1495STim J. Robbinsargument is the bitwise inclusive OR of any of the following constants: 57faea1495STim J. Robbins.Bl -tag -width ".Dv WRDE_SHOWERR" 58faea1495STim J. Robbins.It Dv WRDE_APPEND 590e35e492SRuslan ErmilovAppend the words to those generated by a previous call to 60faea1495STim J. Robbins.Fn wordexp . 61b7114d4aSTim J. Robbins.It Dv WRDE_DOOFFS 62faea1495STim J. RobbinsAs many 63faea1495STim J. Robbins.Dv NULL 64faea1495STim J. Robbinspointers as are specified by the 65faea1495STim J. Robbins.Va we_offs 66faea1495STim J. Robbinsmember of 670e35e492SRuslan Ermilov.Fa we 68faea1495STim J. Robbinsare added to the front of 69faea1495STim J. Robbins.Va we_wordv . 70faea1495STim J. Robbins.It Dv WRDE_NOCMD 71faea1495STim J. RobbinsDisallow command substitution in 72faea1495STim J. Robbins.Fa words . 73faea1495STim J. RobbinsSee the note in 74faea1495STim J. Robbins.Sx BUGS 75faea1495STim J. Robbinsbefore using this. 76faea1495STim J. Robbins.It Dv WRDE_REUSE 77faea1495STim J. RobbinsThe 780e35e492SRuslan Ermilov.Fa we 79faea1495STim J. Robbinsargument was passed to a previous successful call to 80faea1495STim J. Robbins.Fn wordexp 81faea1495STim J. Robbinsbut has not been passed to 82faea1495STim J. Robbins.Fn wordfree . 83faea1495STim J. RobbinsThe implementation may reuse the space allocated to it. 84faea1495STim J. Robbins.It Dv WRDE_SHOWERR 85faea1495STim J. RobbinsDo not redirect shell error messages to 86faea1495STim J. Robbins.Pa /dev/null . 87faea1495STim J. Robbins.It Dv WRDE_UNDEF 88faea1495STim J. RobbinsReport error on an attempt to expand an undefined shell variable. 89faea1495STim J. Robbins.El 90faea1495STim J. Robbins.Pp 91faea1495STim J. RobbinsThe 92faea1495STim J. Robbins.Vt wordexp_t 93faea1495STim J. Robbinsstructure is defined in 94fe08efe6SRuslan Ermilov.In wordexp.h 95faea1495STim J. Robbinsas: 96faea1495STim J. Robbins.Bd -literal -offset indent 97faea1495STim J. Robbinstypedef struct { 98faea1495STim J. Robbins size_t we_wordc; /* count of words matched */ 99faea1495STim J. Robbins char **we_wordv; /* pointer to list of words */ 100faea1495STim J. Robbins size_t we_offs; /* slots to reserve in we_wordv */ 101faea1495STim J. Robbins} wordexp_t; 102faea1495STim J. Robbins.Ed 103faea1495STim J. Robbins.Pp 104faea1495STim J. RobbinsThe 105faea1495STim J. Robbins.Fn wordfree 106faea1495STim J. Robbinsfunction frees the memory allocated by 107faea1495STim J. Robbins.Fn wordexp . 108faea1495STim J. Robbins.Sh IMPLEMENTATION NOTES 109faea1495STim J. RobbinsThe 110faea1495STim J. Robbins.Fn wordexp 111faea1495STim J. Robbinsfunction is implemented as a wrapper around the undocumented 112faea1495STim J. Robbins.Ic wordexp 113faea1495STim J. Robbinsshell built-in command. 114faea1495STim J. Robbins.Sh RETURN VALUES 115faea1495STim J. RobbinsThe 116faea1495STim J. Robbins.Fn wordexp 117faea1495STim J. Robbinsfunction returns zero if successful, otherwise it returns one of the following 118faea1495STim J. Robbinserror codes: 119faea1495STim J. Robbins.Bl -tag -width ".Dv WRDE_NOSPACE" 120faea1495STim J. Robbins.It Dv WRDE_BADCHAR 121faea1495STim J. RobbinsThe 122faea1495STim J. Robbins.Fa words 123faea1495STim J. Robbinsargument contains one of the following unquoted characters: 1240e35e492SRuslan Ermilov.Aq newline , 125faea1495STim J. Robbins.Ql | , 126faea1495STim J. Robbins.Ql & , 127faea1495STim J. Robbins.Ql \&; , 128faea1495STim J. Robbins.Ql < , 129faea1495STim J. Robbins.Ql > , 130faea1495STim J. Robbins.Ql \&( , 131faea1495STim J. Robbins.Ql \&) , 132faea1495STim J. Robbins.Ql { , 133faea1495STim J. Robbins.Ql } . 134faea1495STim J. Robbins.It Dv WRDE_BADVAL 135faea1495STim J. RobbinsAn attempt was made to expand an undefined shell variable and 136faea1495STim J. Robbins.Dv WRDE_UNDEF 137faea1495STim J. Robbinsis set in 138faea1495STim J. Robbins.Fa flags . 139faea1495STim J. Robbins.It Dv WRDE_CMDSUB 140faea1495STim J. RobbinsAn attempt was made to use command substitution and 141faea1495STim J. Robbins.Dv WRDE_NOCMD 142faea1495STim J. Robbinsis set in 143faea1495STim J. Robbins.Fa flags . 144faea1495STim J. Robbins.It Dv WRDE_NOSPACE 145faea1495STim J. RobbinsNot enough memory to store the result. 146faea1495STim J. Robbins.It Dv WRDE_SYNTAX 147faea1495STim J. RobbinsShell syntax error in 148faea1495STim J. Robbins.Fa words . 149faea1495STim J. Robbins.El 150faea1495STim J. Robbins.Pp 151faea1495STim J. RobbinsThe 152faea1495STim J. Robbins.Fn wordfree 153faea1495STim J. Robbinsfunction returns no value. 154faea1495STim J. Robbins.Sh ENVIRONMENT 155faea1495STim J. Robbins.Bl -tag -width ".Ev IFS" 156faea1495STim J. Robbins.It Ev IFS 157faea1495STim J. RobbinsField separator. 158faea1495STim J. Robbins.El 159faea1495STim J. Robbins.Sh EXAMPLES 160faea1495STim J. RobbinsInvoke the editor on all 1610e35e492SRuslan Ermilov.Pa .c 1620e35e492SRuslan Ermilovfiles in the current directory 163faea1495STim J. Robbinsand 164faea1495STim J. Robbins.Pa /etc/motd 165faea1495STim J. Robbins(error checking omitted): 166faea1495STim J. Robbins.Bd -literal -offset indent 167faea1495STim J. Robbinswordexp_t we; 168faea1495STim J. Robbins 169faea1495STim J. Robbinswordexp("${EDITOR:-vi} *.c /etc/motd", &we, 0); 170c499f23bSCeri Daviesexecvp(we.we_wordv[0], we.we_wordv); 171faea1495STim J. Robbins.Ed 172faea1495STim J. Robbins.Sh DIAGNOSTICS 173faea1495STim J. RobbinsDiagnostic messages from the shell are written to the standard error output 174faea1495STim J. Robbinsif 175faea1495STim J. Robbins.Dv WRDE_SHOWERR 176faea1495STim J. Robbinsis set in 177faea1495STim J. Robbins.Fa flags . 178faea1495STim J. Robbins.Sh SEE ALSO 179faea1495STim J. Robbins.Xr sh 1 , 180faea1495STim J. Robbins.Xr fnmatch 3 , 181faea1495STim J. Robbins.Xr glob 3 , 182faea1495STim J. Robbins.Xr popen 3 , 183faea1495STim J. Robbins.Xr system 3 184faea1495STim J. Robbins.Sh STANDARDS 185faea1495STim J. RobbinsThe 186faea1495STim J. Robbins.Fn wordexp 187faea1495STim J. Robbinsand 188faea1495STim J. Robbins.Fn wordfree 189cd203b8eSTim J. Robbinsfunctions conform to 190faea1495STim J. Robbins.St -p1003.1-2001 . 191faea1495STim J. Robbins.Sh BUGS 192faea1495STim J. RobbinsDo not pass untrusted user data to 193faea1495STim J. Robbins.Fn wordexp , 194faea1495STim J. Robbinsregardless of whether the 195faea1495STim J. Robbins.Dv WRDE_NOCMD 196faea1495STim J. Robbinsflag is set. 197faea1495STim J. RobbinsThe 198faea1495STim J. Robbins.Fn wordexp 199faea1495STim J. Robbinsfunction attempts to detect input that would cause commands to be 200faea1495STim J. Robbinsexecuted before passing it to the shell 201faea1495STim J. Robbinsbut it does not use the same parser so it may be fooled. 202f825dd29STim J. Robbins.Pp 203f825dd29STim J. RobbinsThe current 204f825dd29STim J. Robbins.Fn wordexp 205f825dd29STim J. Robbinsimplementation does not recognize multibyte characters, since the 206f825dd29STim J. Robbinsshell (which it invokes to perform expansions) does not. 207