1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
23 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
24 .\" all rights reserved.
25 .\" Translated Sun Sep 12 05:05:19 JST 2004
26 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
28 .TH WORDEXP 3 2008-07-14 "" "Linux Programmer's Manual"
31 .\"O wordexp, wordfree \- perform word expansion like a posix-shell
32 wordexp, wordfree \- posix ¥·¥§¥ë¤Î¤è¤¦¤Ëñ¸ì¤ÎŸ³«¤ò¹Ô¤¦
35 .B "#include <wordexp.h>"
37 .BI "int wordexp(const char *" s ", wordexp_t *" p ", int " flags );
39 .BI "void wordfree(wordexp_t *" p );
42 .\"O Feature Test Macro Requirements for glibc (see
43 .\"O .BR feature_test_macros (7)):
44 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
45 .RB ( feature_test_macros (7)
56 .\"O performs a shell-like expansion of the string
58 .\"O and returns the result in the structure pointed to by
62 ¤Ï¥·¥§¥ë¤Î¤è¤¦¤Ëʸ»úÎó
66 ¤Ç»Ø¤·¼¨¤¹¹½Â¤ÂΤ˷ë²Ì¤òÊÖ¤¹¡£
69 .\"O is a structure that at least has the fields
76 ¤Ï¾¯¤Ê¤¯¤È¤â¥Õ¥£¡¼¥ë¥É
85 .\"O that gives the number of words in the expansion of
93 ¤òŸ³«¤·¤¿·ë²Ì¤Ëñ¸ì¤¬¤¤¤¯¤Ä¤¢¤ë¤«¤òɽ¤¹¡£
98 .\"O that points to the array of words found.
103 ¤Ç¤¢¤ê¡¢¸«¤Ä¤«¤Ã¤¿Ã±¸ì¤ÎÇÛÎó¤ò»Ø¤·¼¨¤¹¡£
108 .\"O is sometimes (depending on
110 .\"O see below) used to indicate the number of initial elements in the
112 .\"O array that should be filled with NULLs.
118 ÇÛÎó¤Ë¤¢¤ë½é´üÍ×ÁǤΤ¦¤Á¤¤¤¯¤Ä¤¬
119 NULL ¤ÇËä¤á¤é¤ì¤ë¤Ù¤¤«¤òɽ¤¹¤Î¤Ë»È¤ï¤ì¤¿¤ê¤¹¤ë
121 ¤Ë¤è¤ê·èÄꤵ¤ì¤ë¡£²¼µ¤ò»²¾È¡£)¡£
125 .\"O frees the allocated memory again.
126 .\"O More precisely, it does not free
127 .\"O its argument, but it frees the array
129 .\"O and the strings that points to.
132 ¤Ï³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤òºÆÅÙ²òÊü¤¹¤ë¡£
133 ¤è¤êÀµ³Î¤Ë¤¤¤¦¤È¡¢¤³¤Î´Ø¿ô¤Ï¤½¤Î°ú¤¿ô¤ò²òÊü¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢
136 ¤È¤½¤ì¤¬»Ø¤·¼¨¤¹Ê¸»úÎó¤ò²òÊü¤¹¤ë¡£
137 .\"O .SS "The string argument"
139 .\"O Since the expansion is the same as the expansion by the shell (see
141 .\"O of the parameters to a command, the string
143 .\"O must not contain characters that would be illegal in shell command
145 .\"O In particular, there must not be any unescaped
146 .\"O newline or |, &, ;, <, >, (, ), {, } characters
147 .\"O outside a command substitution or parameter substitution context.
148 ¤³¤ÎŸ³«¤Ï¥·¥§¥ë¤Ë¤è¤ë¥³¥Þ¥ó¥É¤Î¥Ñ¥é¥á¡¼¥¿¤ÎŸ³«
150 ¤ò»²¾È) ¤ÈƱ¤¸¤Ç¤¢¤ë¤Î¤Ç¡¢Ê¸»úÎó
152 ¤Ï¥·¥§¥ë¥³¥Þ¥ó¥É¥Ñ¥é¥á¡¼¥¿¤ÇÉÔÀµ¤È¤µ¤ì¤ëʸ»ú¤ò´Þ¤ó¤Ç¤Ï¤Ê¤é¤Ê¤¤¡£
153 Æä˥¨¥¹¥±¡¼¥×¤µ¤ì¤Æ¤¤¤Ê¤¤²þ¹Ô¡¢|, &, ;, <, >, (, ), {, } ʸ»ú¤ò
154 ¥³¥Þ¥ó¥ÉÃÖ´¹¤ä¥Ñ¥é¥á¡¼¥¿ÃÖ´¹¤Î¾ìḬ̀ʳ°¤Ë´Þ¤á¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
158 .\"O contains a word that starts with an unquoted comment character #,
159 .\"O then it is unspecified whether that word and all following words
160 .\"O are ignored, or the # is treated as a non-comment character.
163 ¤Ë¥¯¥©¡¼¥È¤·¤Æ¤¤¤Ê¤¤¥³¥á¥ó¥Èʸ»ú # ¤Ç»Ï¤Þ¤ëñ¸ì¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢
164 ¤½¤Îñ¸ì¤È¤½¤ì°Ê¹ß¤Îñ¸ì¤¬Ìµ»ë¤µ¤ì¤ë¤«¡¢
165 ¤½¤ì¤È¤â # ¤¬¥³¥á¥ó¥Èʸ»ú¤È¤·¤Æ°·¤ï¤Ê¤¤¤«¤Ï¡¢µ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
166 .\"O .SS "The expansion"
168 .\"O The expansion done consists of the following stages:
169 .\"O tilde expansion (replacing ~user by user's home directory),
170 .\"O variable substitution (replacing $FOO by the value of the environment
171 .\"O variable FOO), command substitution (replacing $(command) or \`command\`
172 .\"O by the output of command), arithmetic expansion, field splitting,
173 .\"O wildcard expansion, quote removal.
174 ¼Â¹Ô¤µ¤ì¤ëŸ³«¤Ï¡¢°Ê²¼¤ÎÃʳ¬¤Ç¹½À®¤µ¤ì¤ë:
175 ¥Á¥ë¥ÀŸ³« (~user ¤ò user ¤Î¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê¤ËÃÖ¤´¹¤¨¤ë)¡¢
176 ÊÑ¿ôŸ³« ($FOO ¤ò´Ä¶ÊÑ¿ô FOO ¤ÎÃͤËÃÖ¤´¹¤¨¤ë)¡¢
177 ¥³¥Þ¥ó¥ÉŸ³« ($(command) ¤Þ¤¿¤Ï \`command\` ¤ò command ¤Î½ÐÎϤÇÃÖ¤´¹¤¨¤ë)¡¢
178 »»½ÑŸ³«¡¢¥Õ¥£¡¼¥ë¥Éʬ³ä¡¢¥ï¥¤¥ë¥É¥«¡¼¥ÉŸ³«¡¢¥¯¥©¡¼¥È¤Î½üµî¡£
180 .\"O The result of expansion of special parameters
181 .\"O ($@, $*, $#, $?, $\-, $$, $!, $0) is unspecified.
182 Æüì¤Ê¥Ñ¥é¥á¡¼¥¿ ($@, $*, $#, $?, $\-, $$, $!, $0) ¤Î
183 Ÿ³«·ë²Ì¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
185 .\"O Field splitting is done using the environment variable $IFS.
186 .\"O If it is not set, the field separators are space, tab and newline.
187 ¥Õ¥£¡¼¥ë¥Éʬ³ä¤Ï´Ä¶ÊÑ¿ô $IFS ¤òÍѤ¤¤Æ¹Ô¤ï¤ì¤ë¡£
188 ¤³¤Î´Ä¶ÊÑ¿ô¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
189 ¥Õ¥£¡¼¥ë¥É¶èÀÚ¤êʸ»ú¤Ï¥¹¥Ú¡¼¥¹¡¦¥¿¥Ö¡¦²þ¹Ô¤Ç¤¢¤ë¡£
190 .\"O .SS "The output array"
194 .\"O contains the words found, followed by a NULL.
197 ¤Ï¸«¤Ä¤«¤Ã¤¿Ã±¸ì¤ò¤ò´Þ¤ß¡¢ºÇ¸å¤Ë NULL ¤¬Â³¤¯¡£
198 .\"O .SS "The flags argument"
201 .\"O argument is a bitwise inclusive OR of the following values:
204 °ú¤¿ô¤Ï°Ê²¼¤ÎÃͤΥӥåÈÊñ´ÞŪ OR ¤Ç¤¢¤ë:
207 .\"O Append the words found to the array resulting from a previous call.
208 ¸«¤Ä¤«¤Ã¤¿Ã±¸ì¤òÁ°²ó¤Î¸Æ¤Ó½Ð¤··ë²Ì¤ÎÇÛÎó¤ËÄɲ乤롣
213 .\"O initial NULLs in the array
215 .\"O (These are not counted in the returned
221 ¤ËÁÞÆþ¤¹¤ë (¤³¤ì¤é¤ÏÊÖ¤µ¤ì¤ë
223 ¤Ë¤Ï¥«¥¦¥ó¥È¤µ¤ì¤Ê¤¤)¡£
226 .\"O Don't do command substitution.
227 ¥³¥Þ¥ó¥ÉÃÖ´¹¤ò¹Ô¤ï¤Ê¤¤¡£
232 .\"O resulted from a previous call to
237 .\"O Reuse the allocated storage.
242 ¤Î¸Æ¤Ó½Ð¤··ë²Ì¤Ç¤¢¤ê¡¢
244 ¤¬ (¤Þ¤À) ¸Æ¤Ó½Ð¤µ¤ì¤Ê¤¤¡£
245 ³ä¤êÅö¤Æ¤é¤ì¤¿Îΰè¤òºÆÍøÍѤ¹¤ë¡£
248 .\"O Normally during command substitution
250 .\"O is redirected to
252 Ä̾ï¤Ï¥³¥Þ¥ó¥ÉÃÖ´¹¤Î¤È¤¤Ë
256 ¤Ë¥ê¥À¥¤¥ì¥¯¥È¤µ¤ì¤ë¡£
257 .\"O This flag specifies that
259 .\"O is not to be redirected.
262 ¤ò¥ê¥À¥¤¥ì¥¯¥È¤·¤Ê¤¤¤è¤¦¤Ë»ØÄꤹ¤ë¡£
265 .\"O Consider it an error if an undefined shell variable is expanded.
266 ̤ÄêµÁ¤Î¥·¥§¥ëÊÑ¿ô¤òŸ³«¤·¤è¤¦¤È¤·¤¿¾ì¹ç¤Ë¡¢¥¨¥é¡¼¤È¤·¤Æ°·¤¦¡£
267 .\"O .SH "RETURN VALUE"
269 .\"O In case of success 0 is returned.
270 .\"O In case of error
271 .\"O one of the following five values is returned.
272 À®¸ù¤·¤¿¾ì¹ç¤Ï 0 ¤¬ÊÖ¤µ¤ì¤ë¡£
273 ¥¨¥é¡¼¤Î¾ì¹ç¤Ï°Ê²¼¤Î 5 ¤Ä¤ÎÃͤΤ¦¤Á¤Î 1 ¤Ä¤¬ÊÖ¤µ¤ì¤ë¡£
276 .\"O Illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }.
277 ²þ¹Ô¤Þ¤¿¤Ï |, &, ;, <, >, (, ), {, } ¤Î¤¦¤Á¤Î 1 ¤Ä¤¬ÉÔÀµ¤Ë½Ð¸½¤·¤¿¡£
280 .\"O An undefined shell variable was referenced, and the
283 .\"O told us to consider this an error.
284 ̤ÄêµÁ¤Î¥·¥§¥ëÊÑ¿ô¤¬»²¾È¤µ¤ì¡¢¤«¤Ä
286 ¥Õ¥é¥°¤Ç¤³¤ì¤ò¥¨¥é¡¼¤È¤·¤Æ°·¤¦¤è¤¦¤Ë»Ø¼¨¤µ¤ì¤Æ¤¤¤ë¡£
289 .\"O Command substitution occurred, and the
291 .\"O flag told us to consider this an error.
292 ¥³¥Þ¥ó¥ÉÃÖ´¹¤¬µ¯¤³¤ê¡¢¤«¤Ä
294 ¥Õ¥é¥°¤Ç¤³¤ì¤ò¥¨¥é¡¼¤È¤·¤Æ°·¤¦¤è¤¦¤Ë»Ø¼¨¤µ¤ì¤Æ¤¤¤ë¡£
301 .\"O Shell syntax error, such as unbalanced parentheses or
302 .\"O unmatched quotes.
303 Âбþ¤¹¤ë³ç¸Ì¤¬¤Ê¤¤¡¢¥¯¥©¡¼¥È¤¬¹çÃפ·¤Ê¤¤¤È¤¤¤Ã¤¿¡¢
310 .\"O are provided in glibc since version 2.1.
314 ¤Ï¡¢¥Ð¡¼¥¸¥ç¥ó 2.1 °Ê¹ß¤Î glibc ¤ÇÄ󶡤µ¤ì¤Æ¤¤¤ë¡£
315 .\"O .SH "CONFORMING TO"
320 .\"O The output of the following example program
321 .\"O is approximately that of "ls [a-c]*.c".
322 °Ê²¼¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Î½ÐÎϤϤÀ¤¤¤¿¤¤ "ls [a-c]*.c" ¤ÈƱ¤¸¤Ë¤Ê¤ë¡£
330 main(int argc, char **argv)
336 wordexp("[a-c]*.c", &p, 0);
338 for (i = 0; i < p.we_wordc; i++)
339 printf("%s\en", w[i]);