/usr/bin/bash: Difference between revisions

Line 793: Line 793:


=== Pathname Expansion ===
=== Pathname Expansion ===
      After  word splitting, unless the -f option has been set, bash scans each word for the characters
単語分割の後、-fオプションが設定されていない限り、bashは各単語に*? 、[ の文字がないかスキャンする。 これらの文字が1つでも出現し、引用符で囲まれていない場合、その単語はパターンとみなされ、パターンにマッチするファイル名のアルファベット順のリストで置き換えられる(下記の[[#Pattern Matching|Pattern Matching ]]を参照)。 マッチするファイル名が見つからず、シェルオプションのnullglobが有効になっていない場合、その単語は変更されない。 nullglobオプションが設定されていて、マッチするものが見つからない場合、その単語は削除される。 failglobシェル・オプションが設定され、マッチが見つからなかった場合、エラー・メッセージが表示され、コマンドは実行されない。 シェル・オプションnocaseglobが有効な場合、アルファベットの大文字小文字を区別せずにマッチが実行される。 <nowiki>[a-z]</nowiki>(後述)のような範囲式を使う場合、'''LC_COLLATE'''の設定によっては、他の大文字と小文字が含まれる場合があることに注意。 パス名の展開にパターンを使用する場合、シェルオプションの dotglob が設定されていない限り、名前の先頭またはスラッシュの直後の文字 ``.'' は明示的にマッチさせなければならない。 ファイル名の ``.'' ``...' は、dotglobが設定されていても、常に明示的にマッチさせなけれ ばならない。 それ以外の場合、``.''文字は特別に扱われない。 パス名をマッチさせる場合、スラッシュ文字は常にパターン中のスラッシュによって 明示的にマッチさせなければならないが、それ以外のマッチングコンテキストでは、 後述のパターンマッチングのところで説明するように、特別なパターン文字によって マッチさせることができる。 nocaseglob、nullglob、failglob、dotglobシェルオプションの説明については、後述の[[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]のshoptの説明を参照のこと。
      *, ?, and [.  If one of these characters appears, and is not quoted, then the word is regarded as
      a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern (see
      Pattern Matching below).  If no matching filenames are found, and the shell  option  nullglob  is
      not  enabled,  the  word  is  left  unchanged.  If the nullglob option is set, and no matches are
      found, the word is removed.  If the failglob shell option is set, and no matches  are  found,  an
      error  message is printed and the command is not executed.  If the shell option nocaseglob is en‐
      abled, the match is performed without regard to the case of  alphabetic  characters.  Note that
      when  using  range expressions like [a-z] (see below), letters of the other case may be included,
      depending on the setting of LC_COLLATE.  When a pattern is used for pathname expansion, the char‐
      acter  ``.'' at the start of a name or immediately following a slash must be matched explicitly,
      unless the shell option dotglob is set.  The filenames ``.'' and ``..''  must always be  matched
      explicitly,  even  if  dotglob  is set.  In other cases, the ``.'' character is not treated spe‐
      cially.  When matching a pathname, the slash character must always be  matched  explicitly  by  a
      slash in the pattern, but in other matching contexts it can be matched by a special pattern char‐
      acter as described below under Pattern Matching.  See the description of shopt below under  SHELL
      BUILTIN COMMANDS for a description of the nocaseglob, nullglob, failglob, and dotglob shell op‐
      tions.


      The GLOBIGNORE shell variable may be used to restrict the set of file names matching  a  pattern.
'''GLOBIGNORE'''シェル変数を使用して、パターンにマッチするファイル名のセットを制限することができる。
      If GLOBIGNORE is set, each matching file name that also matches one of the patterns in GLOBIGNORE
'''GLOBIGNORE'''が設定されると、'''GLOBIGNORE'''のパターンの1つにもマッチするファイル名が、マッチするファイル名のリストから取り除かれる。 nocaseglobオプションが設定されている場合、'''GLOBIGNORE'''のパターンに対するマッチングは大文字小文字を区別せずに行われる。 ファイル名 ``.'' ``...' は、'''GLOBIGNORE'''が設定され、NULLでない場合、常に無視される。 しかし、'''GLOBIGNORE'''をnullでない値に設定すると、dotglobシェルオプションを有効にする効果があるので、``.''で始まる他のすべてのファイル名がマッチするようになる。 .」で始まるファイル名を無視する旧来の動作を得るには、「.*」を '''GLOBIGNORE'''のパターンの1つにする。 '''GLOBIGNORE'''が設定されていない場合、dotglobオプションは無効になる。 パターンマッチは extglob シェルオプションの設定に従う。
      is removed from the list of matches.  If the nocaseglob option is set, the matching  against  the
      patterns in GLOBIGNORE is performed without regard to case.  The filenames ``.'' and ``..'' are
      always ignored when GLOBIGNORE is set and not null.  However, setting GLOBIGNORE to  a  non-null
      value  has the effect of enabling the dotglob shell option, so all other filenames beginning with
      a ``.'' will match.  To get the old behavior of ignoring filenames beginning with a ``.'',  make
      ``.*'' one of the patterns in GLOBIGNORE.  The dotglob option is disabled when GLOBIGNORE is un‐
      set.  The pattern matching honors the setting of the extglob shell option.


=== Pattern Matching ===
=== Pattern Matching ===