|
|
Line 800: |
Line 800: |
| === Pattern Matching === | | === Pattern Matching === |
|
| |
|
| Any character that appears in a pattern, other than the special pattern characters described be‐
| | 以下に説明する特殊パターン文字以外の、パターン中に現れる文字はすべて、それ自体にマッチする。 NUL文字はパターン中に出現してはならない。 バックスラッシュは次の文字をエスケープする。 特殊パターン文字を文字通りにマッチさせる場合は、引用符で囲む必要がある。 |
| low, matches itself. The NUL character may not occur in a pattern. A backslash escapes the fol‐
| |
| lowing character; the escaping backslash is discarded when matching. The special pattern charac‐
| |
| ters must be quoted if they are to be matched literally.
| |
|
| |
|
| The special pattern characters have the following meanings:
| | 特殊パターン文字は以下の意味を持つ: |
|
| |
|
| * Matches any string, including the null string. When the globstar shell option is
| | ;* |
| enabled, and * is used in a pathname expansion context, two adjacent *s used as a
| | :NULL文字列を含む任意の文字列にマッチする。 globstarシェル・オプションが有効で、*がパス名展開コンテキストで使用されている場合、隣接する2つの*を1つのパターンとして使用すると、すべてのファイルと0個以上のディレクトリおよびサブディレクトリにマッチする。 の後に / が続く場合、隣接する2つの * はディレクトリとサブディレクトリにのみマッチする。 |
| single pattern will match all files and zero or more directories and subdirecto‐
| | ;? |
| ries. If followed by a /, two adjacent *s will match only directories and subdi‐
| | :任意の1文字にマッチする。 |
| rectories.
| | ;<nowiki>[...]</nowiki> |
| ? Matches any single character.
| | :囲まれた文字のいずれかにマッチする。 ハイフンで区切られた2つの文字の組は範囲式を表し、現在のロケールの照合順序と文字セットを 使って、その2つの文字の間にあるすべての文字がマッチする。 に続く最初の文字が「!」または「^」の場合、囲まれていないすべての文字が マッチされる。 範囲式の文字のソート順は、現在のロケールと、'''LC_COLLATE'''または'''LC_ALL'''シェル変数が設定されていればその値によって決定される。 <nowiki>[a-d]</nowiki>が<nowiki>[abcd]</nowiki>と等価であるという範囲式の伝統的な解釈を得るには、 '''LC_ALL'''シェル変数の値をCに設定するか、globasciirangesシェルオプションを有効にする。 - は、セットの最初または最後の文字として含めることでマッチする。 <nowiki>]</nowiki> は、集合の最初の文字として含めることでマッチする。 |
| [...] Matches any one of the enclosed characters. A pair of characters separated by a
| |
| hyphen denotes a range expression; any character that falls between those two char‐
| |
| acters, inclusive, using the current locale's collating sequence and character set,
| |
| is matched. If the first character following the [ is a ! or a ^ then any charac‐
| |
| ter not enclosed is matched. The sorting order of characters in range expressions
| |
| is determined by the current locale and the values of the LC_COLLATE or LC_ALL
| |
| shell variables, if set. To obtain the traditional interpretation of range expres‐
| |
| sions, where [a-d] is equivalent to [abcd], set value of the LC_ALL shell variable
| |
| to C, or enable the globasciiranges shell option. A - may be matched by including
| |
| it as the first or last character in the set. A ] may be matched by including it
| |
| as the first character in the set.
| |
|
| |
|
| Within [ and ], character classes can be specified using the syntax [:class:],
| | <nowiki>[ および ]</nowiki>の中では、<nowiki>[:class:]</nowiki>という構文で文字クラスを指定することができる。classは、 POSIX標準に定義されている以下のクラスの1つである。 word文字クラスは、文字、数字、文字_にマッチする。 |
| where class is one of the following classes defined in the POSIX standard:
| |
| alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
| |
| A character class matches any character belonging to that class. The word charac‐
| |
| ter class matches letters, digits, and the character _.
| |
|
| |
|
| Within [ and ], an equivalence class can be specified using the syntax [=c=], which
| | <nowiki>[ および ]</nowiki> 内では、等価クラスは構文 <nowiki>[=c=]</nowiki> を使って指定することができ、この構文は、文字 c と同じ照合重み(現在のロケールで定義されている)を持つすべての文字にマッチする。 |
| matches all characters with the same collation weight (as defined by the current
| |
| locale) as the character c.
| |
|
| |
|
| Within [ and ], the syntax [.symbol.] matches the collating symbol symbol.
| | <nowiki>[ および ]</nowiki> 内では、構文 <nowiki>[.symbol.]</nowiki> は照合記号 symbol にマッチする。 |
|
| |
|
| If the extglob shell option is enabled using the shopt builtin, several extended pattern matching
| | shopt 組み込み関数で extglob シェルオプションを有効にすると、いくつかの拡張パターンマッチング演算子が認識される。 以下の説明では、pattern-listは|で区切られた1つ以上のパターンのリストである。 複合パターンは、以下のサブパターンの1つ以上を使用して形成することができる: |
| operators are recognized. In the following description, a pattern-list is a list of one or more
| |
| patterns separated by a |. Composite patterns may be formed using one or more of the following
| |
| sub-patterns:
| |
|
| |
|
| ?(pattern-list)
| | ;?(pattern-list) |
| Matches zero or one occurrence of the given patterns
| | :与えられたパターンの0個または1個にマッチする |
| *(pattern-list)
| | ;*(pattern-list) |
| Matches zero or more occurrences of the given patterns
| | :与えられたパターンの0回以上の出現にマッチする |
| +(pattern-list)
| | ;+(pattern-list) |
| Matches one or more occurrences of the given patterns
| | :与えられたパターンの1つ以上の出現にマッチする |
| @(pattern-list)
| | ;@(pattern-list) |
| Matches one of the given patterns
| | :与えられたパターンのいずれかにマッチする |
| !(pattern-list)
| | ;!(pattern-list) |
| Matches anything except one of the given patterns
| | :与えられたパターンの1つ以外とマッチする |
|
| |
|
| Complicated extended pattern matching against long strings is slow, especially when the patterns
| | 長い文字列に対する複雑な拡張パターンマッチングは、特にパターンが交替を含み、文字列が複数のマッチを含む場合、時間がかかる。 短い文字列に対して別々のマッチを使うか、1つの長い文字列の代わりに文字列の配列を使う方が速いかもしれない。 |
| contain alternations and the strings contain multiple matches. Using separate matches against
| |
| shorter strings, or using arrays of strings instead of a single long string, may be faster.
| |
|
| |
|
| === Quote Removal === | | === Quote Removal === |