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.\" 26*d358fa78SJilles Tjoelker.Dd September 30, 2015 27faea1495STim J. Robbins.Dt WORDEXP 3 28faea1495STim J. Robbins.Os 29faea1495STim J. Robbins.Sh NAME 30faea1495STim J. Robbins.Nm wordexp 31faea1495STim J. Robbins.Nd "perform shell-style word expansions" 32faea1495STim J. Robbins.Sh LIBRARY 33faea1495STim J. Robbins.Lb libc 34faea1495STim J. Robbins.Sh SYNOPSIS 35faea1495STim J. Robbins.In wordexp.h 36faea1495STim J. Robbins.Ft int 370e35e492SRuslan Ermilov.Fn wordexp "const char * restrict words" "wordexp_t * restrict we" "int flags" 38be074a2dSTim J. Robbins.Ft void 390e35e492SRuslan Ermilov.Fn wordfree "wordexp_t *we" 40faea1495STim J. Robbins.Sh DESCRIPTION 41faea1495STim J. RobbinsThe 42faea1495STim J. Robbins.Fn wordexp 43faea1495STim J. Robbinsfunction performs shell-style word expansion on 44faea1495STim J. Robbins.Fa words 45faea1495STim J. Robbinsand places the list of words into the 46faea1495STim J. Robbins.Va we_wordv 47faea1495STim J. Robbinsmember of 480e35e492SRuslan Ermilov.Fa we , 49faea1495STim J. Robbinsand the number of words into 50faea1495STim J. Robbins.Va we_wordc . 51faea1495STim J. Robbins.Pp 52faea1495STim J. RobbinsThe 530e35e492SRuslan Ermilov.Fa flags 54faea1495STim J. Robbinsargument is the bitwise inclusive OR of any of the following constants: 55faea1495STim J. Robbins.Bl -tag -width ".Dv WRDE_SHOWERR" 56faea1495STim J. Robbins.It Dv WRDE_APPEND 570e35e492SRuslan ErmilovAppend the words to those generated by a previous call to 58faea1495STim J. Robbins.Fn wordexp . 59b7114d4aSTim J. Robbins.It Dv WRDE_DOOFFS 60faea1495STim J. RobbinsAs many 61faea1495STim J. Robbins.Dv NULL 62faea1495STim J. Robbinspointers as are specified by the 63faea1495STim J. Robbins.Va we_offs 64faea1495STim J. Robbinsmember of 650e35e492SRuslan Ermilov.Fa we 66faea1495STim J. Robbinsare added to the front of 67faea1495STim J. Robbins.Va we_wordv . 68faea1495STim J. Robbins.It Dv WRDE_NOCMD 69faea1495STim J. RobbinsDisallow command substitution in 70faea1495STim J. Robbins.Fa words . 71faea1495STim J. RobbinsSee the note in 72faea1495STim J. Robbins.Sx BUGS 73faea1495STim J. Robbinsbefore using this. 74faea1495STim J. Robbins.It Dv WRDE_REUSE 75faea1495STim J. RobbinsThe 760e35e492SRuslan Ermilov.Fa we 77faea1495STim J. Robbinsargument was passed to a previous successful call to 78faea1495STim J. Robbins.Fn wordexp 79faea1495STim J. Robbinsbut has not been passed to 80faea1495STim J. Robbins.Fn wordfree . 81faea1495STim J. RobbinsThe implementation may reuse the space allocated to it. 82faea1495STim J. Robbins.It Dv WRDE_SHOWERR 83faea1495STim J. RobbinsDo not redirect shell error messages to 84faea1495STim J. Robbins.Pa /dev/null . 85faea1495STim J. Robbins.It Dv WRDE_UNDEF 86faea1495STim J. RobbinsReport error on an attempt to expand an undefined shell variable. 87faea1495STim J. Robbins.El 88faea1495STim J. Robbins.Pp 89faea1495STim J. RobbinsThe 90faea1495STim J. Robbins.Vt wordexp_t 91faea1495STim J. Robbinsstructure is defined in 92fe08efe6SRuslan Ermilov.In wordexp.h 93faea1495STim J. Robbinsas: 94faea1495STim J. Robbins.Bd -literal -offset indent 95faea1495STim J. Robbinstypedef struct { 96faea1495STim J. Robbins size_t we_wordc; /* count of words matched */ 97faea1495STim J. Robbins char **we_wordv; /* pointer to list of words */ 98faea1495STim J. Robbins size_t we_offs; /* slots to reserve in we_wordv */ 99faea1495STim J. Robbins} wordexp_t; 100faea1495STim J. Robbins.Ed 101faea1495STim J. Robbins.Pp 102faea1495STim J. RobbinsThe 103faea1495STim J. Robbins.Fn wordfree 104faea1495STim J. Robbinsfunction frees the memory allocated by 105faea1495STim J. Robbins.Fn wordexp . 106faea1495STim J. Robbins.Sh IMPLEMENTATION NOTES 107faea1495STim J. RobbinsThe 108faea1495STim J. Robbins.Fn wordexp 109*d358fa78SJilles Tjoelkerfunction is implemented using the undocumented 110*d358fa78SJilles Tjoelker.Ic freebsd_wordexp 111*d358fa78SJilles Tjoelkershell built-in command. 112faea1495STim J. Robbins.Sh RETURN VALUES 113faea1495STim J. RobbinsThe 114faea1495STim J. Robbins.Fn wordexp 115faea1495STim J. Robbinsfunction returns zero if successful, otherwise it returns one of the following 116faea1495STim J. Robbinserror codes: 117faea1495STim J. Robbins.Bl -tag -width ".Dv WRDE_NOSPACE" 118faea1495STim J. Robbins.It Dv WRDE_BADCHAR 119faea1495STim J. RobbinsThe 120faea1495STim J. Robbins.Fa words 121faea1495STim J. Robbinsargument contains one of the following unquoted characters: 1220e35e492SRuslan Ermilov.Aq newline , 123faea1495STim J. Robbins.Ql | , 124faea1495STim J. Robbins.Ql & , 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.It Dv WRDE_BADVAL 13389cead33SJilles TjoelkerAn error after successful parsing, 13489cead33SJilles Tjoelkersuch as an attempt to expand an undefined shell variable with 135faea1495STim J. Robbins.Dv WRDE_UNDEF 13689cead33SJilles Tjoelkerset in 137faea1495STim J. Robbins.Fa flags . 138faea1495STim J. Robbins.It Dv WRDE_CMDSUB 139faea1495STim J. RobbinsAn attempt was made to use command substitution and 140faea1495STim J. Robbins.Dv WRDE_NOCMD 141faea1495STim J. Robbinsis set in 142faea1495STim J. Robbins.Fa flags . 143faea1495STim J. Robbins.It Dv WRDE_NOSPACE 14489cead33SJilles TjoelkerNot enough memory to store the result or 14589cead33SJilles Tjoelkeran error during 14689cead33SJilles Tjoelker.Xr fork 2 . 147faea1495STim J. Robbins.It Dv WRDE_SYNTAX 148faea1495STim J. RobbinsShell syntax error in 149faea1495STim J. Robbins.Fa words . 150faea1495STim J. Robbins.El 151faea1495STim J. Robbins.Pp 152faea1495STim J. RobbinsThe 153faea1495STim J. Robbins.Fn wordfree 154faea1495STim J. Robbinsfunction returns no value. 155faea1495STim J. Robbins.Sh ENVIRONMENT 156faea1495STim J. Robbins.Bl -tag -width ".Ev IFS" 157faea1495STim J. Robbins.It Ev IFS 158faea1495STim J. RobbinsField separator. 159faea1495STim J. Robbins.El 160faea1495STim J. Robbins.Sh EXAMPLES 161faea1495STim J. RobbinsInvoke the editor on all 1620e35e492SRuslan Ermilov.Pa .c 1630e35e492SRuslan Ermilovfiles in the current directory 164faea1495STim J. Robbinsand 165faea1495STim J. Robbins.Pa /etc/motd 166faea1495STim J. Robbins(error checking omitted): 167faea1495STim J. Robbins.Bd -literal -offset indent 168faea1495STim J. Robbinswordexp_t we; 169faea1495STim J. Robbins 170faea1495STim J. Robbinswordexp("${EDITOR:-vi} *.c /etc/motd", &we, 0); 171c499f23bSCeri Daviesexecvp(we.we_wordv[0], we.we_wordv); 172faea1495STim J. Robbins.Ed 173faea1495STim J. Robbins.Sh DIAGNOSTICS 174faea1495STim J. RobbinsDiagnostic messages from the shell are written to the standard error output 175faea1495STim J. Robbinsif 176faea1495STim J. Robbins.Dv WRDE_SHOWERR 177faea1495STim J. Robbinsis set in 178faea1495STim J. Robbins.Fa flags . 179faea1495STim J. Robbins.Sh SEE ALSO 180faea1495STim J. Robbins.Xr sh 1 , 181faea1495STim J. Robbins.Xr fnmatch 3 , 182faea1495STim J. Robbins.Xr glob 3 , 183faea1495STim J. Robbins.Xr popen 3 , 184faea1495STim J. Robbins.Xr system 3 185faea1495STim J. Robbins.Sh STANDARDS 186faea1495STim J. RobbinsThe 187faea1495STim J. Robbins.Fn wordexp 188faea1495STim J. Robbinsand 189faea1495STim J. Robbins.Fn wordfree 190cd203b8eSTim J. Robbinsfunctions conform to 191faea1495STim J. Robbins.St -p1003.1-2001 . 192faea1495STim J. Robbins.Sh BUGS 193f825dd29STim J. RobbinsThe current 194f825dd29STim J. Robbins.Fn wordexp 195d7852cbcSBaptiste Daroussinimplementation does not recognize multibyte characters other than UTF-8, since 196d7852cbcSBaptiste Daroussinthe shell (which it invokes to perform expansions) does not. 197*d358fa78SJilles Tjoelker.Sh SECURITY CONSIDERATIONS 198*d358fa78SJilles TjoelkerPathname generation may create output that is exponentially larger than the 199*d358fa78SJilles Tjoelkerinput size. 200*d358fa78SJilles Tjoelker.Pp 201*d358fa78SJilles TjoelkerAlthough this implementation detects command substitution reliably for 202*d358fa78SJilles Tjoelker.Dv WRDE_NOCMD , 203*d358fa78SJilles Tjoelkerthe attack surface remains fairly large. 204*d358fa78SJilles TjoelkerAlso, some other implementations 205*d358fa78SJilles Tjoelker(such as older versions of this one) 206*d358fa78SJilles Tjoelkermay execute command substitutions even if 207*d358fa78SJilles Tjoelker.Dv WRDE_NOCMD 208*d358fa78SJilles Tjoelkeris set. 209