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"
30 wordexp, wordfree \- posix シェルのように単語の展開を行う
32 .B "#include <wordexp.h>"
34 .BI "int wordexp(const char *" s ", wordexp_t *" p ", int " flags );
36 .BI "void wordfree(wordexp_t *" p );
40 .RB ( feature_test_macros (7)
80 NULL で埋められるべきかを表すのに使われたりする
87 より正確にいうと、この関数はその引き数を解放するのではなく、
92 この展開はシェルによるコマンドのパラメータの展開
96 はシェルコマンドパラメータで不正とされる文字を含んではならない。
97 特にエスケープされていない改行、|, &, ;, <, >, (, ), {, } 文字を
98 コマンド置換やパラメータ置換の場面以外に含めてはならない。
102 にクォートしていないコメント文字 # で始まる単語が含まれている場合には、
104 それとも # がコメント文字として扱わないかは、規定されていない。
106 実行される展開は、以下の段階で構成される:
107 チルダ展開 (~user を user のホームディレクトリに置き換える)、
108 変数展開 ($FOO を環境変数 FOO の値に置き換える)、
109 コマンド展開 ($(command) または \`command\` を command の出力で置き換える)、
110 算術展開、フィールド分割、ワイルドカード展開、クォートの除去。
112 特殊なパラメータ ($@, $*, $#, $?, $\-, $$, $!, $0) の
115 フィールド分割は環境変数 $IFS を用いて行われる。
117 フィールド区切り文字はスペース・タブ・改行である。
121 は見つかった単語をを含み、最後に NULL が続く。
124 引き数は以下の値のビット包含的 OR である:
127 見つかった単語を前回の呼び出し結果の配列に追加する。
162 未定義のシェル変数を展開しようとした場合に、エラーとして扱う。
165 エラーの場合は以下の 5 つの値のうちの 1 つが返される。
168 改行または |, &, ;, <, >, (, ), {, } のうちの 1 つが不正に出現した。
173 フラグでこれをエラーとして扱うように指示されている。
178 フラグでこれをエラーとして扱うように指示されている。
184 対応する括弧がない、クォートが合致しないといった、
190 は、バージョン 2.1 以降の glibc で提供されている。
194 以下のサンプルプログラムの出力はだいたい "ls [a-c]*.c" と同じになる。
202 main(int argc, char **argv)
208 wordexp("[a-c]*.c", &p, 0);
210 for (i = 0; i < p.we_wordc; i++)
211 printf("%s\en", w[i]);