OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / wordexp.3
1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
2 .\"
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.
7 .\"
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.
12 .\"
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.
17 .\"
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,
21 .\" USA.
22 .\"
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>
27 .\"
28 .TH WORDEXP 3 2008-07-14  "" "Linux Programmer's Manual"
29 .\"O .SH NAME
30 .SH Ì¾Á°
31 .\"O wordexp, wordfree \- perform word expansion like a posix-shell
32 wordexp, wordfree \- posix ¥·¥§¥ë¤Î¤è¤¦¤Ëñ¸ì¤ÎŸ³«¤ò¹Ô¤¦
33 .\"O .SH SYNOPSIS
34 .SH ½ñ¼°
35 .B "#include <wordexp.h>"
36 .sp
37 .BI "int wordexp(const char *" s ", wordexp_t *" p ", int " flags );
38 .sp
39 .BI "void wordfree(wordexp_t *" p );
40 .sp
41 .in -4n
42 .\"O Feature Test Macro Requirements for glibc (see
43 .\"O .BR feature_test_macros (7)):
44 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
45 .RB ( feature_test_macros (7)
46 »²¾È):
47 .in
48 .sp
49 .BR wordexp (),
50 .BR wordfree ():
51 _XOPEN_SOURCE
52 .\"O .SH DESCRIPTION
53 .SH ÀâÌÀ
54 .\"O The function
55 .\"O .BR wordexp ()
56 .\"O performs a shell-like expansion of the string
57 .\"O .I s
58 .\"O and returns the result in the structure pointed to by
59 .\"O .IR p .
60 ´Ø¿ô
61 .BR wordexp ()
62 ¤Ï¥·¥§¥ë¤Î¤è¤¦¤Ëʸ»úÎó
63 .I s
64 ¤òŸ³«¤·¡¢
65 .I p
66 ¤Ç»Ø¤·¼¨¤¹¹½Â¤ÂΤ˷ë²Ì¤òÊÖ¤¹¡£
67 .\"O The data type
68 .\"O .I wordexp_t
69 .\"O is a structure that at least has the fields
70 .\"O .IR we_wordc ,
71 .\"O .IR we_wordv ,
72 .\"O and
73 .\"O .IR we_offs .
74 ¥Ç¡¼¥¿·¿
75 .I wordexp_t
76 ¤Ï¾¯¤Ê¤¯¤È¤â¥Õ¥£¡¼¥ë¥É
77 .IR we_wordc ,
78 .IR we_wordv ,
79 .I we_offs
80 ¤ò»ý¤Ä¹½Â¤ÂΤǤ¢¤ë¡£
81 .\"O The field
82 .\"O .I we_wordc
83 .\"O is a
84 .\"O .I size_t
85 .\"O that gives the number of words in the expansion of
86 .\"O .IR s .
87 ¥Õ¥£¡¼¥ë¥É
88 .I we_wordc
89 ¤Ï
90 .I size_t
91 ¤Ç¤¢¤ê¡¢
92 .I s
93 ¤òŸ³«¤·¤¿·ë²Ì¤Ëñ¸ì¤¬¤¤¤¯¤Ä¤¢¤ë¤«¤òɽ¤¹¡£
94 .\"O The field
95 .\"O .I we_wordv
96 .\"O is a
97 .\"O .I char **
98 .\"O that points to the array of words found.
99 ¥Õ¥£¡¼¥ë¥É
100 .I we_wordv
101 ¤Ï
102 .I char **
103 ¤Ç¤¢¤ê¡¢¸«¤Ä¤«¤Ã¤¿Ã±¸ì¤ÎÇÛÎó¤ò»Ø¤·¼¨¤¹¡£
104 .\"O The field
105 .\"O .I we_offs
106 .\"O of type
107 .\"O .I size_t
108 .\"O is sometimes (depending on
109 .\"O .IR flags ,
110 .\"O see below) used to indicate the number of initial elements in the
111 .\"O .I we_wordv
112 .\"O array that should be filled with NULLs.
113 .I size_t
114 ·¿¤Î¥Õ¥£¡¼¥ë¥É
115 .I we_offs
116 ¤Ï¡¢
117 .I we_wordv
118 ÇÛÎó¤Ë¤¢¤ë½é´üÍ×ÁǤΤ¦¤Á¤¤¤¯¤Ä¤¬
119 NULL ¤ÇËä¤á¤é¤ì¤ë¤Ù¤­¤«¤òɽ¤¹¤Î¤Ë»È¤ï¤ì¤¿¤ê¤¹¤ë
120 .RI ( flags
121 ¤Ë¤è¤ê·èÄꤵ¤ì¤ë¡£²¼µ­¤ò»²¾È¡£)¡£
122 .LP
123 .\"O The function
124 .\"O .BR wordfree ()
125 .\"O frees the allocated memory again.
126 .\"O More precisely, it does not free
127 .\"O its argument, but it frees the array
128 .\"O .I we_wordv
129 .\"O and the strings that points to.
130 ´Ø¿ô
131 .BR wordfree ()
132 ¤Ï³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤òºÆÅÙ²òÊü¤¹¤ë¡£
133 ¤è¤êÀµ³Î¤Ë¤¤¤¦¤È¡¢¤³¤Î´Ø¿ô¤Ï¤½¤Î°ú¤­¿ô¤ò²òÊü¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢
134 ÇÛÎó
135 .I we_wordv
136 ¤È¤½¤ì¤¬»Ø¤·¼¨¤¹Ê¸»úÎó¤ò²òÊü¤¹¤ë¡£
137 .\"O .SS "The string argument"
138 .SS "ʸ»úÎó°ú¤­¿ô"
139 .\"O Since the expansion is the same as the expansion by the shell (see
140 .\"O .BR sh (1))
141 .\"O of the parameters to a command, the string
142 .\"O .I s
143 .\"O must not contain characters that would be illegal in shell command
144 .\"O parameters.
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 ¤³¤ÎŸ³«¤Ï¥·¥§¥ë¤Ë¤è¤ë¥³¥Þ¥ó¥É¤Î¥Ñ¥é¥á¡¼¥¿¤ÎŸ³«
149 .RB ( sh (1)
150 ¤ò»²¾È) ¤ÈƱ¤¸¤Ç¤¢¤ë¤Î¤Ç¡¢Ê¸»úÎó
151 .I s
152 ¤Ï¥·¥§¥ë¥³¥Þ¥ó¥É¥Ñ¥é¥á¡¼¥¿¤ÇÉÔÀµ¤È¤µ¤ì¤ëʸ»ú¤ò´Þ¤ó¤Ç¤Ï¤Ê¤é¤Ê¤¤¡£
153 Æä˥¨¥¹¥±¡¼¥×¤µ¤ì¤Æ¤¤¤Ê¤¤²þ¹Ô¡¢|, &, ;, <, >, (, ), {, } Ê¸»ú¤ò
154 ¥³¥Þ¥ó¥ÉÃÖ´¹¤ä¥Ñ¥é¥á¡¼¥¿ÃÖ´¹¤Î¾ìḬ̀ʳ°¤Ë´Þ¤á¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
155 .LP
156 .\"O If the argument
157 .\"O .I s
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.
161 °ú¤­¿ô
162 .I s
163 ¤Ë¥¯¥©¡¼¥È¤·¤Æ¤¤¤Ê¤¤¥³¥á¥ó¥Èʸ»ú # ¤Ç»Ï¤Þ¤ëñ¸ì¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢
164 ¤½¤Îñ¸ì¤È¤½¤ì°Ê¹ß¤Îñ¸ì¤¬Ìµ»ë¤µ¤ì¤ë¤«¡¢
165 ¤½¤ì¤È¤â # ¤¬¥³¥á¥ó¥Èʸ»ú¤È¤·¤Æ°·¤ï¤Ê¤¤¤«¤Ï¡¢µ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
166 .\"O .SS "The expansion"
167 .SS "Ÿ³«"
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 »»½ÑŸ³«¡¢¥Õ¥£¡¼¥ë¥Éʬ³ä¡¢¥ï¥¤¥ë¥É¥«¡¼¥ÉŸ³«¡¢¥¯¥©¡¼¥È¤Î½üµî¡£
179 .LP
180 .\"O The result of expansion of special parameters
181 .\"O ($@, $*, $#, $?, $\-, $$, $!, $0) is unspecified.
182 Æüì¤Ê¥Ñ¥é¥á¡¼¥¿ ($@, $*, $#, $?, $\-, $$, $!, $0) ¤Î
183 Ÿ³«·ë²Ì¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
184 .LP
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"
191 .SS "½ÐÎϤµ¤ì¤ëÇÛÎó"
192 .\"O The array
193 .\"O .I we_wordv
194 .\"O contains the words found, followed by a NULL.
195 ÇÛÎó
196 .I we_wordv
197 ¤Ï¸«¤Ä¤«¤Ã¤¿Ã±¸ì¤ò¤ò´Þ¤ß¡¢ºÇ¸å¤Ë NULL ¤¬Â³¤¯¡£
198 .\"O .SS "The flags argument"
199 .\"O The
200 .\"O .I flag
201 .\"O argument is a bitwise inclusive OR of the following values:
202 .SS "flags °ú¤­¿ô"
203 .I flags
204 °ú¤­¿ô¤Ï°Ê²¼¤ÎÃͤΥӥåÈÊñ´ÞŪ OR ¤Ç¤¢¤ë:
205 .TP
206 .B WRDE_APPEND
207 .\"O Append the words found to the array resulting from a previous call.
208 ¸«¤Ä¤«¤Ã¤¿Ã±¸ì¤òÁ°²ó¤Î¸Æ¤Ó½Ð¤··ë²Ì¤ÎÇÛÎó¤ËÄɲ乤롣
209 .TP
210 .B WRDE_DOOFFS
211 .\"O Insert
212 .\"O .I we_offs
213 .\"O initial NULLs in the array
214 .\"O .IR we_wordv .
215 .\"O (These are not counted in the returned
216 .\"O .IR we_wordc .)
217 ½é´ü¾õÂ֤Ǥ¢¤ë
218 .I we_offs
219 ¸Ä¤Î NULL ¤òÇÛÎó
220 .I we_wordv
221 ¤ËÁÞÆþ¤¹¤ë (¤³¤ì¤é¤ÏÊÖ¤µ¤ì¤ë
222 .I we_wordc
223 ¤Ë¤Ï¥«¥¦¥ó¥È¤µ¤ì¤Ê¤¤)¡£
224 .TP
225 .B WRDE_NOCMD
226 .\"O Don't do command substitution.
227 ¥³¥Þ¥ó¥ÉÃÖ´¹¤ò¹Ô¤ï¤Ê¤¤¡£
228 .TP
229 .B WRDE_REUSE
230 .\"O The argument
231 .\"O .I p
232 .\"O resulted from a previous call to
233 .\"O .BR wordexp (),
234 .\"O and
235 .\"O .BR wordfree ()
236 .\"O was not called.
237 .\"O Reuse the allocated storage.
238 °ú¤­¿ô
239 .I p
240 ¤ÏÁ°²ó¤Î
241 .BR wordexp ()
242 ¤Î¸Æ¤Ó½Ð¤··ë²Ì¤Ç¤¢¤ê¡¢
243 .BR wordfree ()
244 ¤¬ (¤Þ¤À) ¸Æ¤Ó½Ð¤µ¤ì¤Ê¤¤¡£
245 ³ä¤êÅö¤Æ¤é¤ì¤¿Îΰè¤òºÆÍøÍѤ¹¤ë¡£
246 .TP
247 .B WRDE_SHOWERR
248 .\"O Normally during command substitution
249 .\"O .I stderr
250 .\"O is redirected to
251 .\"O .IR /dev/null .
252 Ä̾ï¤Ï¥³¥Þ¥ó¥ÉÃÖ´¹¤Î¤È¤­¤Ë
253 .I stderr
254 ¤¬
255 .I /dev/null
256 ¤Ë¥ê¥À¥¤¥ì¥¯¥È¤µ¤ì¤ë¡£
257 .\"O This flag specifies that
258 .\"O .I stderr
259 .\"O is not to be redirected.
260 ¤³¤Î¥Õ¥é¥°¤Ï
261 .I stderr
262 ¤ò¥ê¥À¥¤¥ì¥¯¥È¤·¤Ê¤¤¤è¤¦¤Ë»ØÄꤹ¤ë¡£
263 .TP
264 .B WRDE_UNDEF
265 .\"O Consider it an error if an undefined shell variable is expanded.
266 ̤ÄêµÁ¤Î¥·¥§¥ëÊÑ¿ô¤òŸ³«¤·¤è¤¦¤È¤·¤¿¾ì¹ç¤Ë¡¢¥¨¥é¡¼¤È¤·¤Æ°·¤¦¡£
267 .\"O .SH "RETURN VALUE"
268 .SH ÊÖ¤êÃÍ
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 ¤Ä¤¬ÊÖ¤µ¤ì¤ë¡£
274 .TP
275 .B WRDE_BADCHAR
276 .\"O Illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }.
277 ²þ¹Ô¤Þ¤¿¤Ï |, &, ;, <, >, (, ), {, } ¤Î¤¦¤Á¤Î 1 ¤Ä¤¬ÉÔÀµ¤Ë½Ð¸½¤·¤¿¡£
278 .TP
279 .B WRDE_BADVAL
280 .\"O An undefined shell variable was referenced, and the
281 .\"O .B WRDE_UNDEF
282 .\"O flag
283 .\"O told us to consider this an error.
284 ̤ÄêµÁ¤Î¥·¥§¥ëÊÑ¿ô¤¬»²¾È¤µ¤ì¡¢¤«¤Ä
285 .B WRDE_UNDEF
286 ¥Õ¥é¥°¤Ç¤³¤ì¤ò¥¨¥é¡¼¤È¤·¤Æ°·¤¦¤è¤¦¤Ë»Ø¼¨¤µ¤ì¤Æ¤¤¤ë¡£
287 .TP
288 .B WRDE_CMDSUB
289 .\"O Command substitution occurred, and the
290 .\"O .B WRDE_NOCMD
291 .\"O flag told us to consider this an error.
292 ¥³¥Þ¥ó¥ÉÃÖ´¹¤¬µ¯¤³¤ê¡¢¤«¤Ä
293 .B WRDE_NOCMD
294 ¥Õ¥é¥°¤Ç¤³¤ì¤ò¥¨¥é¡¼¤È¤·¤Æ°·¤¦¤è¤¦¤Ë»Ø¼¨¤µ¤ì¤Æ¤¤¤ë¡£
295 .TP
296 .B WRDE_NOSPACE
297 .\"O Out of memory.
298 ¥á¥â¥ê¤¬Â­¤ê¤Ê¤¤¡£
299 .TP
300 .B WRDE_SYNTAX
301 .\"O Shell syntax error, such as unbalanced parentheses or
302 .\"O unmatched quotes.
303 Âбþ¤¹¤ë³ç¸Ì¤¬¤Ê¤¤¡¢¥¯¥©¡¼¥È¤¬¹çÃפ·¤Ê¤¤¤È¤¤¤Ã¤¿¡¢
304 ¥·¥§¥ë¤Î½ñ¼°¥¨¥é¡¼¡£
305 .\"O .SH VERSIONS
306 .SH ¥Ð¡¼¥¸¥ç¥ó
307 .\"O .BR wordexp ()
308 .\"O and
309 .\"O .BR wordfree ()
310 .\"O are provided in glibc since version 2.1.
311 .BR wordexp ()
312 ¤È
313 .BR wordfree ()
314 ¤Ï¡¢¥Ð¡¼¥¸¥ç¥ó 2.1 °Ê¹ß¤Î glibc ¤ÇÄ󶡤µ¤ì¤Æ¤¤¤ë¡£
315 .\"O .SH "CONFORMING TO"
316 .SH ½àµò
317 POSIX.1-2001.
318 .\"O .SH EXAMPLE
319 .SH Îã
320 .\"O The output of the following example program
321 .\"O is approximately that of "ls [a-c]*.c".
322 °Ê²¼¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Î½ÐÎϤϤÀ¤¤¤¿¤¤ "ls [a-c]*.c" ¤ÈƱ¤¸¤Ë¤Ê¤ë¡£
323 .LP
324 .nf
325 #include <stdio.h>
326 #include <stdlib.h>
327 #include <wordexp.h>
328
329 int
330 main(int argc, char **argv)
331 {
332     wordexp_t p;
333     char **w;
334     int i;
335
336     wordexp("[a-c]*.c", &p, 0);
337     w = p.we_wordv;
338     for (i = 0; i < p.we_wordc; i++)
339         printf("%s\en", w[i]);
340     wordfree(&p);
341     exit(EXIT_SUCCESS);
342 }
343 .fi
344 .\"O .SH "SEE ALSO"
345 .SH ´ØÏ¢¹àÌÜ
346 .BR fnmatch (3),
347 .BR glob (3)