OSDN Git Service

0e316bc6163180ae04989933ffe0ba350d9a842a
[linuxjm/LDP_man-pages.git] / draft / man7 / glob.7
1 .\" Copyright (c) 1998 Andries Brouwer
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 .\" 2003-08-24 fix for / by John Kristoff + joey
24 .\"
25 .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
26 .\" Translated Wed 12 Aug 1998 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
27 .\" Updated 2003-09-28 by NAKANO Takeo
28 .\"
29 .\"WORD:        wild card pattern       ワイルドカードパターン
30 .\"WORD:        character class         文字クラス
31 .\"WORD:        range                   領域指定
32 .\"WORD:        complementation         補集合
33 .\"WORD:        regular expression      正規表現
34 .\"WORD:        bracket expression      ブラケット表現
35 .\"WORD:        collating sequence      照合順序
36 .\"WORD:        collating element       照合順序の要素
37 .\"WORD:        current locale          カレントロケール
38 .\"WORD:        equivalence class       等価クラス
39 .\"
40 .TH GLOB 7 2003-08-24 "Linux" "Linux Programmer's Manual"
41 .\"O .SH NAME
42 .SH 名前
43 .\"O glob \- Globbing pathnames
44 glob \- パス名を glob する
45 .\"O .SH DESCRIPTION
46 .SH 説明
47 .\"O Long ago, in UNIX V6, there was a program
48 .\"O .I /etc/glob
49 .\"O that would expand wildcard patterns.
50 .\"O Soon afterward this became a shell built-in.
51 昔々 UNIX V6 では、ワイルドカードパターンを展開する
52 .I /etc/glob
53 と言うプログラムがあった。その後すぐに、
54 この機能はシェルに組み込まれるようになった。
55
56 .\"O These days there is also a library routine
57 .\"O .BR glob (3)
58 .\"O that will perform this function for a user program.
59 今日では、この機能をユーザープログラムからも実行できるよう、
60 .BR glob (3)
61 というライブラリルーチンも存在している。
62
63 .\"O The rules are as follows (POSIX.2, 3.13).
64 glob の規則を以下に述べる (POSIX.2 3.13)。
65 .\"O .SS "Wildcard Matching"
66 .SS ワイルドカードマッチ
67 .\"O A string is a wildcard pattern if it contains one of the
68 .\"O characters \(aq?\(aq, \(aq*\(aq or \(aq[\(aq.
69 .\"O Globbing is the operation
70 .\"O that expands a wildcard pattern into the list of pathnames
71 .\"O matching the pattern.
72 .\"O Matching is defined by:
73 文字列に \(aq?\(aq, \(aq*\(aq, \(aq[\(aq が含まれていると、
74 それはワイルドカードパターンとみなされる。
75 「glob する」というのは、ワイルドカードパターンを展開して、
76 そのパターンにマッチするパス名のリストを得ることである。
77 マッチは以下のように定義される。
78
79 .\"O A \(aq?\(aq (not between brackets) matches any single character.
80 (ブラケット外部の) \(aq?\(aq はあらゆる単一の文字にマッチする。
81
82 .\"O A \(aq*\(aq (not between brackets) matches any string,
83 .\"O including the empty string.
84 (ブラケット外部の) \(aq*\(aq はあらゆる文字列にマッチする。
85 空文字列 (empty string) にもマッチする。
86 .PP
87 .\"O .B "Character classes"
88 .B "文字クラス (character class)"
89 .sp
90 .\"O An expression "\fI[...]\fP" where the first character after the
91 .\"O leading \(aq[\(aq is not an \(aq!\(aq matches a single character,
92 .\"O namely any of the characters enclosed by the brackets.
93 .\"O The string enclosed by the brackets cannot be empty;
94 .\"O therefore \(aq]\(aq can be allowed between the brackets, provided
95 .\"O that it is the first character.
96 .\"O (Thus, "\fI[][!]\fP" matches the
97 .\"O three characters \(aq[\(aq, \(aq]\(aq and \(aq!\(aq.)
98 "\fI[...]\fP" と言う表記は、先頭の \(aq[\(aq に続く最初の文字が \(aq!\(aq で
99 なければ、ブラケットの中に含まれている文字のどれか一つにマッチする。
100 ブラケットの内部に含まれる文字列は空であってはならない。
101 したがって \(aq]\(aq も最初の文字に指定すればブラケットの内部に含めることが
102 できる (つまり "\fI[][!]\fP" は \(aq[\(aq, \(aq]\(aq, \(aq!\(aq の
103 3 文字のどれかにマッチする)。
104 .PP
105 .\"O .B Ranges
106 .B "領域指定 (range)"
107 .sp
108 .\"O There is one special convention:
109 .\"O two characters separated by \(aq\-\(aq denote a range.
110 .\"O (Thus, "\fI[A\-Fa\-f0\-9]\fP"
111 .\"O is equivalent to "\fI[ABCDEFabcdef0123456789]\fP".)
112 .\"O One may include \(aq\-\(aq in its literal meaning by making it the
113 .\"O first or last character between the brackets.
114 .\"O (Thus, "\fI[]\-]\fP" matches just the two characters \(aq]\(aq and \(aq\-\(aq,
115 .\"O and "\fI[\-\-0]\fP" matches the
116 .\"O three characters \(aq\-\(aq, \(aq.\(aq, \(aq0\(aq, since \(aq/\(aq
117 .\"O cannot be matched.)
118 特殊な表記法が一つ存在する。\(aq\-\(aq を挟む二つの文字は領域指定となる。
119 (つまり "\fI[A\-Fa\-f0\-9]\fP" は "\fI[ABCDEFabcdef0123456789]\fP"
120 と等価となる。) \(aq\-\(aq 文字そのものを入れたい場合は、
121 ブラケットの先頭または最後の文字に指定すればよい。
122 (つまり "\fI[]\-]\fP" は二つの文字 \(aq]\(aq と \(aq\-\(aq
123 にマッチし、"\fI[\-\-0]\fP" は \(aq\-\(aq, \(aq.\(aq, \(aq0\(aq の
124 3 文字にマッチする。この間の \(aq/\(aq にはマッチしない。後述を参照。)
125 .PP
126 .\"O .B Complementation
127 .B 補集合 (complementation)
128 .sp
129 .\"O An expression "\fI[!...]\fP" matches a single character, namely
130 .\"O any character that is not matched by the expression obtained
131 .\"O by removing the first \(aq!\(aq from it.
132 .\"O (Thus, "\fI[!]a\-]\fP" matches any
133 .\"O single character except \(aq]\(aq, \(aqa\(aq and \(aq\-\(aq.)
134 "\fI[!...]\fP" と言う表記は、ブラケットの内部に含まれない単一の文字にマッチする
135 (ただし先頭にある \(aq!\(aq は除外)。 (つまり "\fI[!]a\-]\fP" は
136 \(aq]\(aq, \(aqa\(aq, \(aq\-\(aq 以外のすべての文字の、どれか一つにマッチする。)
137
138 .\"O One can remove the special meaning of \(aq?\(aq, \(aq*\(aq and \(aq[\(aq by
139 .\"O preceding them by a backslash, or, in case this is part of
140 .\"O a shell command line, enclosing them in quotes.
141 .\"O Between brackets these characters stand for themselves.
142 .\"O Thus, "\fI[[?*\e]\fP" matches the
143 .\"O four characters \(aq[\(aq, \(aq?\(aq, \(aq*\(aq and \(aq\e\(aq.
144 バックスラッシュ \(aq\e\(aq を前置すれば、 \(aq?\(aq, \(aq*\(aq, \(aq[\(aq
145 は通常の文字として扱われる。
146 またはシェルのコマンドラインの一部に指定する場合は、
147 クォートで囲っても同じ効果が得られる。ブラケットの内部では、
148 これらの文字はその文字自身だけを意味する。
149 すなわち "\fI[[?*\e]\fP" は \(aq[\(aq, \(aq?\(aq, \(aq*\(aq, \(aq\e\(aq
150 のどれか一文字にマッチする。
151 .\"O .SS Pathnames
152 .SS "パス名 (pathname)"
153 .\"O Globbing is applied on each of the components of a pathname
154 .\"O separately.
155 .\"O A \(aq/\(aq in a pathname cannot be matched by a \(aq?\(aq or \(aq*\(aq
156 .\"O wildcard, or by a range like "\fI[.\-0]\fP".
157 .\"O A range cannot contain an
158 .\"O explicit \(aq/\(aq character; this would lead to a syntax error.
159 glob 動作は、パス名のそれぞれの部分に独立に適用される。
160 パス名に存在する \(aq/\(aq は \(aq?\(aq や \(aq*\(aq ワイルドカードにはマッチしない。
161 また "\fI[.\-0]\fP" のような領域指定にもマッチしない。
162 領域指定は陽に \(aq/\(aq 文字を含むことはできない。これは文法エラーとなる。
163
164 .\"O If a filename starts with a \(aq.\(aq,
165 .\"O this character must be matched explicitly.
166 .\"O (Thus, \fIrm\ *\fP will not remove .profile, and \fItar\ c\ *\fP will not
167 .\"O archive all your files; \fItar\ c\ .\fP is better.)
168 \(aq.\(aq で始まるパス名では、この文字は陽にマッチさせなければならない。
169 (つまり \fIrm\ *\fP は .profile を削除しない。また \fItar\ c\ *\fP
170 ではすべてのファイルはアーカイブされない。 \fItar\ c\ .\fP の方が良い。)
171 .\"O .SS "Empty Lists"
172 .SS 空のリスト
173 .\"O The nice and simple rule given above: "expand a wildcard pattern
174 .\"O into the list of matching pathnames" was the original UNIX
175 .\"O definition.
176 .\"O It allowed one to have patterns that expand into
177 .\"O an empty list, as in
178 先に与えた、わかりやすく簡単なルール、
179 「ワイルドカードパターンをマッチしたパス名のリストに展開する」と言うのは、
180 オリジナルの UNIX における定義であった。
181 これはパターンが空のリストに展開されることも許可されていた。
182 例えば
183 .br
184 .nf
185     xv \-wait 0 *.gif *.jpg
186 .fi
187 .\"O where perhaps no *.gif files are present (and this is not
188 .\"O an error).
189 において、*.gif ファイルが全くない場合でも、
190 これは空のリストに展開されるため、エラーにならない。
191 .\"O However, POSIX requires that a wildcard pattern is left
192 .\"O unchanged when it is syntactically incorrect, or the list of
193 .\"O matching pathnames is empty.
194 .\"O With
195 .\"O .I bash
196 .\"O one can force the classical behavior by setting
197 .\"O .IR allow_null_glob_expansion=true .
198 しかし POSIX では、文法的に正しくないパターンや、
199 マッチがなかったパターンは、
200 そのまま変更されずに残されることになっている。
201 .I bash
202 では
203 .I allow_null_glob_expansion=true
204 を指定することで、以前の振る舞いに設定することができる。
205
206 .\"O (Similar problems occur elsewhere.
207 .\"O E.g., where old scripts have
208 (同様の問題は別のところでも起こっている。例えば、古いスクリプトにおける
209 .br
210 .nf
211     rm \`find . \-name "*~"\`
212 .fi
213 .\"O new scripts require
214 のような記述は、新しいスクリプトでは
215 .br
216 .nf
217     rm \-f nosuchfile \`find . \-name "*~"\`
218 .fi
219 .\"O to avoid error messages from
220 .\"O .I rm
221 .\"O called with an empty argument list.)
222 のようにしなければならない。さもないと
223 .I rm
224 を引き数リストなしで呼び出す可能性があり、
225 エラーメッセージが出てしまう。)
226 .\"O .SH NOTES
227 .SH 注意
228 .\"O .SS Regular expressions
229 .SS 正規表現
230 .\"O Note that wildcard patterns are not regular expressions,
231 .\"O although they are a bit similar.
232 .\"O First of all, they match
233 .\"O filenames, rather than text, and secondly, the conventions
234 .\"O are not the same: for example, in a regular expression \(aq*\(aq means zero or
235 .\"O more copies of the preceding thing.
236 ワイルドカードパターンは正規表現と多少似ているが、しかしこの両者は異なる。
237 まず第一に、前者がファイル名にマッチするのに対して、
238 後者はテキストにマッチする。第二に、ルールも同じではない。
239 例えば正規表現における \(aq*\(aq は、
240 前置された文字の 0 以上の繰り返しを表す。
241
242 .\"O Now that regular expressions have bracket expressions where
243 .\"O the negation is indicated by a \(aq^\(aq, POSIX has declared the
244 .\"O effect of a wildcard pattern "\fI[^...]\fP" to be undefined.
245 正規表現にもブラケット表現はあるが、否定は \(aq^\(aq でなされる。
246 POSIX ではワイルドカードパターンにおける "\fI[^...]\fP" を未定義であるとしている。
247 .\"O .SS Character classes and Internationalization
248 .SS 文字クラスと国際化
249 .\"O Of course ranges were originally meant to be ASCII ranges,
250 .\"O so that "\fI[\ \-%]\fP" stands for "\fI[\ !"#$%]\fP" and "\fI[a\-z]\fP" stands
251 .\"O for "any lowercase letter".
252 .\"O Some UNIX implementations generalized this so that a range X\-Y
253 .\"O stands for the set of characters with code between the codes for
254 .\"O X and for Y.
255 .\"O However, this requires the user to know the
256 .\"O character coding in use on the local system, and moreover, is
257 .\"O not convenient if the collating sequence for the local alphabet
258 .\"O differs from the ordering of the character codes.
259 領域指定は、もともとはもちろん ASCII における順序並びを意味していた。
260 したがって "\fI[\ \-%]\fP" は "\fI[\ !"#$%]\fP" の意味であり、
261 "\fI[a\-z]\fP" は「すべての小文字」の意味であった。
262 UNIX の実装の中には、これを拡張したものが存在し、
263 そこでは X\-Y という領域指定は、X のコードと
264 Y のコードに挟まれたコードを持つ文字すべてを表すようになっていた。
265 しかし、これにはユーザーがローカルなシステムにおける
266 文字コードを知らなければならず、
267 さらにローカルなアルファベットに対する照合順序
268 (collating sequence) が文字コードの順序と異なっている場合には不便であった。
269 (訳注: collating sequence に関しては
270 .BR regex (7)
271 を参照して下さい。)
272 .\"O Therefore, POSIX extended the bracket notation greatly,
273 .\"O both for wildcard patterns and for regular expressions.
274 .\"O In the above we saw three types of items that can occur in a bracket
275 .\"O expression: namely (i) the negation, (ii) explicit single characters,
276 .\"O and (iii) ranges.
277 .\"O POSIX specifies ranges in an internationally
278 .\"O more useful way and adds three more types:
279 したがって POSIX では、ワイルドカードパターンと正規表現の双方において、
280 ブラケット表記を大幅に拡張している。
281 これまで我々は、ブラケット表記には三つの要素が含まれうることを見てきた。
282 すなわち (i) 否定、(ii) 単一の文字、(iii) 領域指定、の三つである。
283 POSIX では、領域指定をより国際化に便利なように定義しており、
284 また三つのタイプをブラケット表記の要素として追加している。
285
286 .\"O (iii) Ranges X\-Y comprise all characters that fall between X
287 .\"O and Y (inclusive) in the currect collating sequence as defined
288 .\"O by the
289 .\"O .B LC_COLLATE
290 .\"O category in the current locale.
291 (iii) 領域指定 X\-Y は X と Y に挟まれた (両端含む) すべての文字を意味する。
292 このとき、カレントロケール (current locale) の
293 .B LC_COLLATE
294 カテゴリで定義されている照合順序が用いられる。
295
296 .\"O (iv) Named character classes, like
297 (iv) 名前付き文字クラス: 以下のようなものである。
298 .nf
299
300 [:alnum:]  [:alpha:]  [:blank:]  [:cntrl:]
301 [:digit:]  [:graph:]  [:lower:]  [:print:]
302 [:punct:]  [:space:]  [:upper:]  [:xdigit:]
303
304 .fi
305 .\"O so that one can say "\fI[[:lower:]]\fP" instead of "\fI[a\-z]\fP", and have
306 .\"O things work in Denmark, too, where there are three letters past \(aqz\(aq
307 .\"O in the alphabet.
308 .\"O These character classes are defined by the
309 .\"O .B LC_CTYPE
310 .\"O category
311 .\"O in the current locale.
312 これを用いれば "\fI[a\-z]\fP" の代わりに "\fI[[:lower:]]\fP" のような指定ができる。
313 またデンマークのように、アルファベットの \(aqz\(aq 以降に
314 3 つの文字が存在するような場合でも、同じような動作が期待できる。
315 これらの文字クラスはカレントロケールの
316 .B LC_CTYPE
317 カテゴリで定義されている。
318
319 .\"O (v) Collating symbols, like "\fI[.ch.]\fP" or "\fI[.a-acute.]\fP",
320 .\"O where the string between "\fI[.\fP" and "\fI.]\fP" is a collating
321 .\"O element defined for the current locale.
322 .\"O Note that this may
323 .\"O be a multicharacter element.
324 (v) 照合順序におけるシンボル: "\fI[.ch.]\fP" や "\fI[.a-acute.]\fP" のように "\fI[.\fP"
325 と "\fI.]\fP" で挟まれた文字列は、カレントロケールで定義された照合順序の要素となる。
326 ある一つの要素が複数の文字からなる場合もありうることに注意。
327
328 .\"O (vi) Equivalence class expressions, like "\fI[=a=]\fP",
329 .\"O where the string between "\fI[=\fP" and "\fI=]\fP" is any collating
330 .\"O element from its equivalence class, as defined for the
331 .\"O current locale.
332 .\"O For example, "\fI[[=a=]]\fP" might be equivalent
333 .\"O .\" FIXME . the accented 'a' characters are not rendering properly
334 .\"O .\" mtk May 2007
335 .\"O to "\fI[aaaaa]\fP" (warning: Latin-1 here), that is,
336 .\"O to "\fI[a[.a-acute.][.a-grave.][.a-umlaut.][.a-circumflex.]]\fP".
337 (vi) 等価クラス表現 (equivalence class expressions): "\fI[=a=]\fP"
338 のように "\fI[=\fP" と "\fI=]\fP" とで挟まれた文字列である。
339 これは等価クラスのメンバーである照合順序の要素すべてになる。
340 等価クラスはカレントロケールで定義されているものになる。
341 例えば、"\fI[[=a=]]\fP" は
342 "\fI[a[.a\-acute.][.a\-grave.][.a\-umlaut.][.a\-circumflex.]]\fP"
343 と等価である
344 (Latin-1 表記では [a\e`{a}\e'{a}\e"{a}\e^{a}] も同じ。
345 [訳注] 日本語の roff ページでは latin1 コードが出ないので、
346 ここでは TeX 表記で記載)。
347 .\"O .SH "SEE ALSO"
348 .SH 関連項目
349 .BR sh (1),
350 .BR fnmatch (3),
351 .BR glob (3),
352 .BR locale (7),
353 .BR regex (7)