| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- perform word expansions
#include <wordexp.h>intwordexp(const char *restrictwords,wordexp_t *restrictpwordexp,intflags);
voidwordfree(wordexp_t *pwordexp);
Thewordexp() function performs word expansions, subject to quoting, and places the listof expanded words into the structure pointed to bypwordexp.
Thewordfree() function frees any memory allocated bywordexp() associated withpwordexp.
Thewords argument is a pointer to a string containing one ormore words to be expanded. The expansions will be the same aswould be performed by the shell ifwords were the part ofa command line representing the arguments to a utility. Therefore,words mustnot contain an unquoted NEWLINE or any of the unquoted shell specialcharacters:
| & ; < >
except in the context of command substitution. It also must not containunquoted parentheses or braces, except in the context of command or variablesubstitution. If the argumentwords contains an unquoted comment character (number sign)that is the beginning of a token,wordexp() may treat the commentcharacter as a regular character, or may interpret it as a commentindicator and ignore the remainder ofwords.
The structure typewordexp_t is defined in the header <wordexp.h> and includesat least the following members:
Count of words matched bywords.
Pointer to list of expanded words.
Slots to reserve at the beginning ofpwordexp->we_wordv.
Thewordexp() function stores the number of generated words intopwordexp->we_wordc anda pointer to a list of pointers to words inpwordexp->we_wordv. Eachindividual field created during field splitting is a separate word in thepwordexp->we_wordvlist. The words are in order. The first pointer after thelast word pointer will be a null pointer.
It is the caller's responsibility to allocate the storage pointed to bypwordexp. Thewordexp() function allocates other space as needed, including memory pointedto bypwordexp->we_wordv. Thewordfree() function frees any memory associated withpwordexpfrom a previous call towordexp().
Theflags argument is used to control the behavior ofwordexp(). Thevalue offlags is the bitwise inclusive OR of zero or moreof the following constants, which are defined in<wordexp.h>:
Append words generated to the ones from a previous call towordexp().
Make use ofpwordexp->we_offs. If this flag is set,pwordexp->we_offs is used to specify how manyNULL pointers to add to the beginning ofpwordexp->we_wordv. In other words,pwordexp->we_wordv will point topwordexp->we_offsNULL pointers, followed bypwordexp->we_wordc word pointers, followed by aNULL pointer.
Fail if command substitution is requested.
Thepwordexp argument was passed to a previous successful call towordexp(), and has not been passed towordfree(). The result will be the same as if the application had calledwordfree() and then calledwordexp() withoutWRDE_REUSE.
Do not redirectstderr to/dev/null.
Report error on an attempt to expand an undefined shell variable.
TheWRDE_APPEND flag can be used to append a new set ofwords to those generated by a previous call towordexp(). The followingrules apply when two or more calls towordexp() are made withthe same value ofpwordexp and without intervening calls towordfree():
The first such call must not setWRDE_APPEND. All subsequent calls must set it.
All of the calls must setWRDE_DOOFFS, or all must not set it.
After the second and each subsequent call,pwordexp->we_wordv will point to a list containing the following:
zero or moreNULL pointers, as specified byWRDE_DOOFFS andpwordexp->we_offs.
pointers to the words that were in thepwordexp->we_wordv list before the call, in the same order as before.
pointers to the new words generated by the latest call, in the specified order.
The count returned inpwordexp->we_wordc will be the total number of words from all of the calls.
The application can change any of the fields after a call towordexp(), but if it does it must reset them to the original value before a subsequent call, using the samepwordexp value, towordfree() orwordexp() with theWRDE_APPEND orWRDE_REUSE flag.
Ifwords contains an unquoted:
NEWLINE| & ; < > ( ) { }
in an inappropriate context,wordexp() will fail, and the number of expandedwords will be zero.
UnlessWRDE_SHOWERR is set inflags,wordexp() will redirectstderr to/dev/nullfor any utilities executed as a result of command substitution while expandingwords.
IfWRDE_SHOWERR is set,wordexp() may write messages tostderr if syntaxerrors are detected while expandingwords. IfWRDE_DOOFFS is set, thenpwordexp-> we_offsmust have the same value for eachwordexp() call andwordfree() callusing a givenpwordexp.
The following constants are defined as error return values:
One of the unquoted characters:
NEWLINE| & ; < > ( ) { }
appears inwords in an inappropriate context.
Reference to undefined shell variable whenWRDE_UNDEF is set inflags.
Command substitution requested whenWRDE_NOCMD was set in flags.
Attempt to allocate memory failed.
Shell syntax error, such as unbalanced parentheses or unterminated string.
On successful completion,wordexp() returns0.
Otherwise, a non-zero value as described in<wordexp.h> is returned to indicatean error. Ifwordexp() returns the valueWRDE_NOSPACE, thenpwordexp->we_wordc andpwordexp->we_wordv will be updated to reflect any words that were successfully expanded.In other cases, they will not be modified.
Thewordfree() function returns no value.
No errors are defined.
This function is intended to be used by an application that wantsto do all of the shell's expansions on a word or wordsobtained from a user. For example, if the application prompts for afilename (or list of filenames) and then useswordexp() to process theinput, the user could respond with anything that would be valid as inputto the shell.
TheWRDE_NOCMD flag is provided for applications that, for security or otherreasons, want to prevent a user from executing shell command. Disallowing unquotedshell special characters also prevents unwanted side effects such as executing acommand or writing a file.
Seeattributes(5) for descriptions of the following attributes:
|
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |