📄 wordfree.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>wordexp</title></head><body bgcolor="white"><basefont size="3"> <a name="wordexp"></a> <a name="tag_03_864"></a><!-- wordexp --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_864_01"></a>NAME</h4><blockquote>wordexp, wordfree - perform word expansions</blockquote><h4><a name="tag_03_864_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/wordexp.h.html">wordexp.h</a>><br><br> int wordexp(const char *restrict</tt> <i>words</i><tt>, wordexp_t *restrict</tt> <i>pwordexp</i><tt>,<br> int</tt> <i>flags</i><tt>);<br> void wordfree(wordexp_t *</tt><i>pwordexp</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_864_03"></a>DESCRIPTION</h4><blockquote><p>The <i>wordexp</i>() function shall perform word expansions as described in the Shell and Utilities volume ofIEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_06">Section 2.6, Word Expansions</a>, subject toquoting as in the Shell and Utilities volume of IEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_02">Section 2.2, Quoting</a>, and place the list of expanded words into the structure pointedto by <i>pwordexp</i>.</p><p>The <i>words</i> argument is a pointer to a string containing one or more words to be expanded. The expansions shall be the sameas would be performed by the command line interpreter if <i>words</i> were the part of a command line representing the arguments toa utility. Therefore, the application shall ensure that <i>words</i> does not contain an unquoted <newline> or any of theunquoted shell special characters <tt>'|'</tt> , <tt>'&'</tt> , <tt>';'</tt> , <tt>'<'</tt> , <tt>'>'</tt> except in thecontext of command substitution as specified in the Shell and Utilities volume of IEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_06_03">Section 2.6.3, Command Substitution</a>. It also shall not contain unquoted parenthesesor braces, except in the context of command or variable substitution. The application shall ensure that every member of<i>words</i> which it expects to have expanded by <i>wordexp</i>() does not contain an unquoted initial comment character. Theapplication shall also ensure that any words which it intends to be ignored (because they begin or continue a comment) are deletedfrom <i>words</i>. If the argument <i>words</i> contains an unquoted comment character (number sign) that is the beginning of atoken, <i>wordexp</i>() shall either treat the comment character as a regular character, or interpret it as a comment indicator andignore the remainder of <i>words</i>.</p><p>The structure type <b>wordexp_t</b> is defined in the <a href="../basedefs/wordexp.h.html"><i><wordexp.h></i></a> headerand includes at least the following members:</p><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Member Type</b></p></th><th align="center"><p class="tent"><b>Member Name</b></p></th><th align="center"><p class="tent"><b>Description</b></p></th></tr><tr valign="top"><td align="left"><p class="tent"><b>size_t</b></p></td><td align="left"><p class="tent"><i>we_wordc</i></p></td><td align="left"><p class="tent">Count of words matched by <i>words</i>.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>char **</b></p></td><td align="left"><p class="tent"><i>we_wordv</i></p></td><td align="left"><p class="tent">Pointer to list of expanded words.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>size_t</b></p></td><td align="left"><p class="tent"><i>we_offs</i></p></td><td align="left"><p class="tent">Slots to reserve at the beginning of <i>pwordexp</i>-><i>we_wordv</i>.</p></td></tr></table></center><p>The <i>wordexp</i>() function shall store the number of generated words into <i>pwordexp</i>-><i>we_wordc</i> and a pointerto a list of pointers to words in <i>pwordexp</i>-><i>we_wordv</i>. Each individual field created during field splitting (seethe Shell and Utilities volume of IEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_06_05">Section2.6.5, Field Splitting</a>) or pathname expansion (see the Shell and Utilities volume of IEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_06_06">Section 2.6.6, Pathname Expansion</a>) shall be a separate word in the<i>pwordexp</i>-><i>we_wordv</i> list. The words shall be in order as described in the Shell and Utilities volume ofIEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_06">Section 2.6, Word Expansions</a>. The firstpointer after the last word pointer shall be a null pointer. The expansion of special parameters described in the Shell andUtilities volume of IEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_05_02">Section 2.5.2, SpecialParameters</a> is unspecified.</p><p>It is the caller's responsibility to allocate the storage pointed to by <i>pwordexp</i>. The <i>wordexp</i>() function shallallocate other space as needed, including memory pointed to by <i>pwordexp</i>-><i>we_wordv</i>. The <i>wordfree</i>() functionfrees any memory associated with <i>pwordexp</i> from a previous call to <i>wordexp</i>().</p><p>The <i>flags</i> argument is used to control the behavior of <i>wordexp</i>(). The value of <i>flags</i> is thebitwise-inclusive OR of zero or more of the following constants, which are defined in <a href="../basedefs/wordexp.h.html"><i><wordexp.h></i></a>:</p><dl compact><dt>WRDE_APPEND</dt><dd>Append words generated to the ones from a previous call to <i>wordexp</i>().</dd><dt>WRDE_DOOFFS</dt><dd>Make use of <i>pwordexp</i>-><i>we_offs</i>. If this flag is set, <i>pwordexp</i>-><i>we_offs</i> is used to specify howmany null pointers to add to the beginning of <i>pwordexp</i>-><i>we_wordv</i>. In other words,<i>pwordexp</i>-><i>we_wordv</i> shall point to <i>pwordexp</i>-><i>we_offs</i> null pointers, followed by<i>pwordexp</i>-><i>we_wordc</i> word pointers, followed by a null pointer.</dd><dt>WRDE_NOCMD</dt><dd>If the implementation supports the utilities defined in the Shell and Utilities volume of IEEE Std 1003.1-2001, failif command substitution, as specified in the Shell and Utilities volume of IEEE Std 1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_06_03">Section 2.6.3, Command Substitution</a>, is requested.</dd><dt>WRDE_REUSE</dt><dd>The <i>pwordexp</i> argument was passed to a previous successful call to <i>wordexp</i>(), and has not been passed to<i>wordfree</i>(). The result shall be the same as if the application had called <i>wordfree</i>() and then called <i>wordexp</i>()without WRDE_REUSE.</dd><dt>WRDE_SHOWERR</dt><dd>Do not redirect <i>stderr</i> to <b>/dev/null</b>.</dd><dt>WRDE_UNDEF</dt><dd>Report error on an attempt to expand an undefined shell variable.</dd></dl><p>The WRDE_APPEND flag can be used to append a new set of words to those generated by a previous call to <i>wordexp</i>(). Thefollowing rules apply to applications when two or more calls to <i>wordexp</i>() are made with the same value of <i>pwordexp</i>and without intervening calls to <i>wordfree</i>():</p><ol><li><p>The first such call shall not set WRDE_APPEND. All subsequent calls shall set it.</p></li><li><p>All of the calls shall set WRDE_DOOFFS, or all shall not set it.</p></li><li><p>After the second and each subsequent call, <i>pwordexp</i>-><i>we_wordv</i> shall point to a list containing thefollowing:</p><ol type="a"><li><p>Zero or more null pointers, as specified by WRDE_DOOFFS and <i>pwordexp</i>-><i>we_offs</i></p></li><li><p>Pointers to the words that were in the <i>pwordexp</i>-><i>we_wordv</i> list before the call, in the same order as before</p></li><li><p>Pointers to the new words generated by the latest call, in the specified order</p></li></ol></li><li><p>The count returned in <i>pwordexp</i>-><i>we_wordc</i> shall be the total number of words from all of the calls.</p></li><li><p>The application can change any of the fields after a call to <i>wordexp</i>(), but if it does it shall reset them to theoriginal value before a subsequent call, using the same <i>pwordexp</i> value, to <i>wordfree</i>() or <i>wordexp</i>() with theWRDE_APPEND or WRDE_REUSE flag.</p></li></ol><p>If the implementation supports the utilities defined in the Shell and Utilities volume of IEEE Std 1003.1-2001, and<i>words</i> contains an unquoted character- <newline>, <tt>'|'</tt> , <tt>'&'</tt> , <tt>';'</tt> , <tt>'<'</tt> ,<tt>'>'</tt> , <tt>'('</tt> , <tt>')'</tt> , <tt>'{'</tt> , <tt>'}'</tt> - in an inappropriate context, <i>wordexp</i>() shall
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -