OSDN Git Service

7d9c36eb6188b8c181c8e2ef80200e4ca69eaa5f
[linuxjm/LDP_man-pages.git] / 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)