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)):
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
69 .\"O is a structure that at least has the fields
85 .\"O that gives the number of words in the expansion of
98 .\"O that points to the array of words found.
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.
119 NULL で埋められるべきかを表すのに使われたりする
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.
133 より正確にいうと、この関数はその引き数を解放するのではなく、
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 この展開はシェルによるコマンドのパラメータの展開
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 にクォートしていないコメント文字 # で始まる単語が含まれている場合には、
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) の
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 を用いて行われる。
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
226 .\"O Don't do command substitution.
232 .\"O resulted from a previous call to
237 .\"O Reuse the allocated storage.
248 .\"O Normally during command substitution
250 .\"O is redirected to
257 .\"O This flag specifies that
259 .\"O is not to be redirected.
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.
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.
286 フラグでこれをエラーとして扱うように指示されている。
289 .\"O Command substitution occurred, and the
291 .\"O flag told us to consider this an error.
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]);