.\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl) .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. .\" .\" Japanese Version Copyright (c) 2004 Yuichi SATO .\" all rights reserved. .\" Translated Sun Sep 12 05:05:19 JST 2004 .\" by Yuichi SATO .\" .TH WORDEXP 3 2008-07-14 "" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O wordexp, wordfree \- perform word expansion like a posix-shell wordexp, wordfree \- posix シェルのように単語の展開を行う .\"O .SH SYNOPSIS .SH 書式 .B "#include " .sp .BI "int wordexp(const char *" s ", wordexp_t *" p ", int " flags ); .sp .BI "void wordfree(wordexp_t *" p ); .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR wordexp (), .BR wordfree (): _XOPEN_SOURCE .\"O .SH DESCRIPTION .SH 説明 .\"O The function .\"O .BR wordexp () .\"O performs a shell-like expansion of the string .\"O .I s .\"O and returns the result in the structure pointed to by .\"O .IR p . 関数 .BR wordexp () はシェルのように文字列 .I s を展開し、 .I p で指し示す構造体に結果を返す。 .\"O The data type .\"O .I wordexp_t .\"O is a structure that at least has the fields .\"O .IR we_wordc , .\"O .IR we_wordv , .\"O and .\"O .IR we_offs . データ型 .I wordexp_t は少なくともフィールド .IR we_wordc , .IR we_wordv , .I we_offs を持つ構造体である。 .\"O The field .\"O .I we_wordc .\"O is a .\"O .I size_t .\"O that gives the number of words in the expansion of .\"O .IR s . フィールド .I we_wordc は .I size_t であり、 .I s を展開した結果に単語がいくつあるかを表す。 .\"O The field .\"O .I we_wordv .\"O is a .\"O .I char ** .\"O that points to the array of words found. フィールド .I we_wordv は .I char ** であり、見つかった単語の配列を指し示す。 .\"O The field .\"O .I we_offs .\"O of type .\"O .I size_t .\"O is sometimes (depending on .\"O .IR flags , .\"O see below) used to indicate the number of initial elements in the .\"O .I we_wordv .\"O array that should be filled with NULLs. .I size_t 型のフィールド .I we_offs は、 .I we_wordv 配列にある初期要素のうちいくつが NULL で埋められるべきかを表すのに使われたりする .RI ( flags により決定される。下記を参照。)。 .LP .\"O The function .\"O .BR wordfree () .\"O frees the allocated memory again. .\"O More precisely, it does not free .\"O its argument, but it frees the array .\"O .I we_wordv .\"O and the strings that points to. 関数 .BR wordfree () は割り当てたメモリを再度解放する。 より正確にいうと、この関数はその引き数を解放するのではなく、 配列 .I we_wordv とそれが指し示す文字列を解放する。 .\"O .SS "The string argument" .SS "文字列引き数" .\"O Since the expansion is the same as the expansion by the shell (see .\"O .BR sh (1)) .\"O of the parameters to a command, the string .\"O .I s .\"O must not contain characters that would be illegal in shell command .\"O parameters. .\"O In particular, there must not be any unescaped .\"O newline or |, &, ;, <, >, (, ), {, } characters .\"O outside a command substitution or parameter substitution context. この展開はシェルによるコマンドのパラメータの展開 .RB ( sh (1) を参照) と同じであるので、文字列 .I s はシェルコマンドパラメータで不正とされる文字を含んではならない。 特にエスケープされていない改行、|, &, ;, <, >, (, ), {, } 文字を コマンド置換やパラメータ置換の場面以外に含めてはならない。 .LP .\"O If the argument .\"O .I s .\"O contains a word that starts with an unquoted comment character #, .\"O then it is unspecified whether that word and all following words .\"O are ignored, or the # is treated as a non-comment character. 引き数 .I s にクォートしていないコメント文字 # で始まる単語が含まれている場合には、 その単語とそれ以降の単語が無視されるか、 それとも # がコメント文字として扱わないかは、規定されていない。 .\"O .SS "The expansion" .SS "展開" .\"O The expansion done consists of the following stages: .\"O tilde expansion (replacing ~user by user's home directory), .\"O variable substitution (replacing $FOO by the value of the environment .\"O variable FOO), command substitution (replacing $(command) or \`command\` .\"O by the output of command), arithmetic expansion, field splitting, .\"O wildcard expansion, quote removal. 実行される展開は、以下の段階で構成される: チルダ展開 (~user を user のホームディレクトリに置き換える)、 変数展開 ($FOO を環境変数 FOO の値に置き換える)、 コマンド展開 ($(command) または \`command\` を command の出力で置き換える)、 算術展開、フィールド分割、ワイルドカード展開、クォートの除去。 .LP .\"O The result of expansion of special parameters .\"O ($@, $*, $#, $?, $\-, $$, $!, $0) is unspecified. 特殊なパラメータ ($@, $*, $#, $?, $\-, $$, $!, $0) の 展開結果は規定されていない。 .LP .\"O Field splitting is done using the environment variable $IFS. .\"O If it is not set, the field separators are space, tab and newline. フィールド分割は環境変数 $IFS を用いて行われる。 この環境変数が設定されていない場合、 フィールド区切り文字はスペース・タブ・改行である。 .\"O .SS "The output array" .SS "出力される配列" .\"O The array .\"O .I we_wordv .\"O contains the words found, followed by a NULL. 配列 .I we_wordv は見つかった単語をを含み、最後に NULL が続く。 .\"O .SS "The flags argument" .\"O The .\"O .I flag .\"O argument is a bitwise inclusive OR of the following values: .SS "flags 引き数" .I flags 引き数は以下の値のビット包含的 OR である: .TP .B WRDE_APPEND .\"O Append the words found to the array resulting from a previous call. 見つかった単語を前回の呼び出し結果の配列に追加する。 .TP .B WRDE_DOOFFS .\"O Insert .\"O .I we_offs .\"O initial NULLs in the array .\"O .IR we_wordv . .\"O (These are not counted in the returned .\"O .IR we_wordc .) 初期状態である .I we_offs 個の NULL を配列 .I we_wordv に挿入する (これらは返される .I we_wordc にはカウントされない)。 .TP .B WRDE_NOCMD .\"O Don't do command substitution. コマンド置換を行わない。 .TP .B WRDE_REUSE .\"O The argument .\"O .I p .\"O resulted from a previous call to .\"O .BR wordexp (), .\"O and .\"O .BR wordfree () .\"O was not called. .\"O Reuse the allocated storage. 引き数 .I p は前回の .BR wordexp () の呼び出し結果であり、 .BR wordfree () が (まだ) 呼び出されない。 割り当てられた領域を再利用する。 .TP .B WRDE_SHOWERR .\"O Normally during command substitution .\"O .I stderr .\"O is redirected to .\"O .IR /dev/null . 通常はコマンド置換のときに .I stderr が .I /dev/null にリダイレクトされる。 .\"O This flag specifies that .\"O .I stderr .\"O is not to be redirected. このフラグは .I stderr をリダイレクトしないように指定する。 .TP .B WRDE_UNDEF .\"O Consider it an error if an undefined shell variable is expanded. 未定義のシェル変数を展開しようとした場合に、エラーとして扱う。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O In case of success 0 is returned. .\"O In case of error .\"O one of the following five values is returned. 成功した場合は 0 が返される。 エラーの場合は以下の 5 つの値のうちの 1 つが返される。 .TP .B WRDE_BADCHAR .\"O Illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }. 改行または |, &, ;, <, >, (, ), {, } のうちの 1 つが不正に出現した。 .TP .B WRDE_BADVAL .\"O An undefined shell variable was referenced, and the .\"O .B WRDE_UNDEF .\"O flag .\"O told us to consider this an error. 未定義のシェル変数が参照され、かつ .B WRDE_UNDEF フラグでこれをエラーとして扱うように指示されている。 .TP .B WRDE_CMDSUB .\"O Command substitution occurred, and the .\"O .B WRDE_NOCMD .\"O flag told us to consider this an error. コマンド置換が起こり、かつ .B WRDE_NOCMD フラグでこれをエラーとして扱うように指示されている。 .TP .B WRDE_NOSPACE .\"O Out of memory. メモリが足りない。 .TP .B WRDE_SYNTAX .\"O Shell syntax error, such as unbalanced parentheses or .\"O unmatched quotes. 対応する括弧がない、クォートが合致しないといった、 シェルの書式エラー。 .\"O .SH VERSIONS .SH バージョン .\"O .BR wordexp () .\"O and .\"O .BR wordfree () .\"O are provided in glibc since version 2.1. .BR wordexp () と .BR wordfree () は、バージョン 2.1 以降の glibc で提供されている。 .\"O .SH "CONFORMING TO" .SH 準拠 POSIX.1-2001. .\"O .SH EXAMPLE .SH 例 .\"O The output of the following example program .\"O is approximately that of "ls [a-c]*.c". 以下のサンプルプログラムの出力はだいたい "ls [a-c]*.c" と同じになる。 .LP .nf #include #include #include int main(int argc, char **argv) { wordexp_t p; char **w; int i; wordexp("[a-c]*.c", &p, 0); w = p.we_wordv; for (i = 0; i < p.we_wordc; i++) printf("%s\en", w[i]); wordfree(&p); exit(EXIT_SUCCESS); } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .BR fnmatch (3), .BR glob (3)