[BACK]Return to wordexp.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

File: [cvs.NetBSD.org] / src / lib / libc / gen / wordexp.3 (download)

Revision 1.2, Mon Apr 24 20:27:34 2006 UTC (17 years, 11 months ago) by jld
Branch: MAIN
CVS Tags: yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, wrstuden-fixsa-newbase, wrstuden-fixsa-base-1, wrstuden-fixsa-base, wrstuden-fixsa, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, netbsd-4-base, netbsd-4-0-RELEASE, netbsd-4-0-RC5, netbsd-4-0-RC4, netbsd-4-0-RC3, netbsd-4-0-RC2, netbsd-4-0-RC1, netbsd-4-0-1-RELEASE, netbsd-4-0, netbsd-4, mjf-devfs2-base, mjf-devfs2, matt-premerge-20091211, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-premerge-20101231, matt-mips64-base2, matt-mips64-base, matt-mips64, matt-armv6-prevmlocking, matt-armv6-nbase, matt-armv6-base, matt-armv6, localcount-20160914, keiichi-mipv6-base, keiichi-mipv6, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, hpcarm-cleanup-nbase, hpcarm-cleanup-base, hpcarm-cleanup, cube-autoconf-base, cube-autoconf, christos-time_t-nbase, christos-time_t-base, christos-time_t, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, abandoned-netbsd-4-base, abandoned-netbsd-4
Changes since 1.1: +2 -2 lines

\*[Am] for an ampersand, not *[Am].

.\"	$NetBSD: wordexp.3,v 1.2 2006/04/24 20:27:34 jld Exp $
.\"
.\" Copyright (c) 2002 Tim J. Robbins
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/wordexp.3,v 1.6 2003/09/08 19:57:14 ru Exp $
.\"
.Dd July 13, 2004
.Dt WORDEXP 3
.Os
.Sh NAME
.Nm wordexp
.Nd "perform shell-style word expansions"
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In wordexp.h
.Ft int
.Fn wordexp "const char * restrict words" "wordexp_t * restrict pwordexp" "int flags"
.Ft void
.Fn wordfree "wordexp_t *pwordexp"
.Sh DESCRIPTION
The
.Fn wordexp
function performs shell-style word expansion on
.Fa words
and places the list of expanded words into the structure pointed to by
.Fa pwordexp .
.Pp
The
.Fa flags
argument is the bitwise inclusive OR of any of the following constants:
.Bl -tag -width ".Dv WRDE_SHOWERR"
.It Dv WRDE_APPEND
Append the words to those generated by a previous call to
.Fn wordexp .
.It Dv WRDE_DOOFFS
As many
.Dv NULL
pointers as are specified by the
.Va we_offs
member of
.Fa we
are added to the front of
.Va we_wordv .
.It Dv WRDE_NOCMD
Disallow command substitution in
.Fa words .
See the note in
.Sx BUGS
before using this.
.It Dv WRDE_REUSE
The
.Fa we
argument was passed to a previous successful call to
.Fn wordexp
but has not been passed to
.Fn wordfree .
The implementation may reuse the space allocated to it.
.It Dv WRDE_SHOWERR
Do not redirect shell error messages to
.Pa /dev/null .
.It Dv WRDE_UNDEF
Report error on an attempt to expand an undefined shell variable.
.El
.Pp
The structure type
.Nm wordexp_t
includes the following members:
.Bd -literal -offset indent
size_t	we_wordc
char	**we_wordv
size_t	we_offs
.Ed
.Pp
The
.Fa we_wordc
member is the count of generated words.
.Pp
The
.Fa we_wordv
member points to a list of pointers to expanded words.
.Pp
The
.Fa we_offs
member is the number of slots to reserve at the beginning of the
.Fa we_wordv
member.
.Pp
It is the caller's responsibility to allocate the storage pointed to by
.Fa pwordexp .
The
.Fn wordexp
function allocates other space as needed, including memory
pointed to by the
.Fa we_wordv
member.
.Pp
The
.Fn wordfree
function frees the memory allocated by
.Fn wordexp .
.Sh IMPLEMENTATION NOTES
The
.Fn wordexp
function is implemented as a wrapper around the undocumented
.Ic wordexp
shell built-in command.
.Sh RETURN VALUES
The
.Fn wordexp
function returns zero if successful, otherwise it returns one of the following
error codes:
.Bl -tag -width ".Dv WRDE_NOSPACE"
.It Dv WRDE_BADCHAR
The
.Fa words
argument contains one of the following unquoted characters:
.Aq newline ,
.Ql | ,
.Ql \*[Am] ,
.Ql \&; ,
.Ql \*[Lt] ,
.Ql \*[Gt] ,
.Ql \&( ,
.Ql \&) ,
.Ql { ,
.Ql } .
.It Dv WRDE_BADVAL
An attempt was made to expand an undefined shell variable and
.Dv WRDE_UNDEF
is set in
.Fa flags .
.It Dv WRDE_CMDSUB
An attempt was made to use command substitution and
.Dv WRDE_NOCMD
is set in
.Fa flags .
.It Dv WRDE_NOSPACE
Not enough memory to store the result.
.It Dv WRDE_SYNTAX
Shell syntax error in
.Fa words .
.It Dv WRDE_ERRNO
An internal error occured and
.Va errno
is set to indicate the error.
.El
.Pp
The
.Fn wordfree
function returns no value.
.Sh ENVIRONMENT
.Bl -tag -width ".Ev IFS"
.It Ev IFS
Field separator.
.El
.Sh EXAMPLES
Invoke the editor on all
.Pa .c
files in the current directory
and
.Pa /etc/motd
(error checking omitted):
.Bd -literal -offset indent
wordexp_t we;

wordexp("${EDITOR:-vi} *.c /etc/motd", \*[Am]we, 0);
execvp(we-\*[Gt]we_wordv[0], we-\*[Gt]we_wordv);
.Ed
.Sh DIAGNOSTICS
Diagnostic messages from the shell are written to the standard error output
if
.Dv WRDE_SHOWERR
is set in
.Fa flags .
.Sh SEE ALSO
.Xr sh 1 ,
.Xr fnmatch 3 ,
.Xr glob 3 ,
.Xr popen 3 ,
.Xr system 3
.Sh STANDARDS
The
.Fn wordexp
and
.Fn wordfree
functions conform to
.St -p1003.1-2001 .
Their first release was in
.St -p1003.2-92 .
The return value
.Dv WRDE_ERRNO
is an extension.
.Sh BUGS
Do not pass untrusted user data to
.Fn wordexp ,
regardless of whether the
.Dv WRDE_NOCMD
flag is set.
The
.Fn wordexp
function attempts to detect input that would cause commands to be
executed before passing it to the shell
but it does not use the same parser so it may be fooled.