/usr/bin/bash: Difference between revisions

Line 634: Line 634:


=== Brace Expansion ===
=== Brace Expansion ===
      Brace  expansion  is  a mechanism by which arbitrary strings may be generated.  This mechanism is
ブレース展開とは、任意の文字列を生成する仕組みである。 この仕組みはパス名展開と似ているが、生成されるファイル名は存在する必要はない。 ブレース展開されるパターンは、オプションのプリアンブルの後に、カンマで区切られた一連の文字列か、中括弧の間のシーケンス式が続き、その後にオプションの追記が続くという形式をとる。プリアンブルは、中括弧内に含まれる各文字列の先頭に付加され、その後、左から右に展開されながら、結果の各文字列に追記される。
      similar to pathname expansion, but the filenames generated need not exist.  Patterns to be  brace
      expanded  take  the  form of an optional preamble, followed by either a series of comma-separated
      strings or a sequence expression between a pair of braces, followed by  an  optional  postscript.
      The  preamble  is prefixed to each string contained within the braces, and the postscript is then
      appended to each resulting string, expanding left to right.


      Brace expansions may be nested.  The results of each expanded string  are  not  sorted;  left  to
中括弧の展開は入れ子にすることができる。 各展開文字列の結果はソートされない。 例えば、<nowiki>a{d,c,b}e</nowiki>は`ade ace abe'に展開される。
      right order is preserved.  For example, a{d,c,b}e expands into `ade ace abe'.


      A  sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single
シーケンス式は<nowiki>{x..y[..incr]}</nowiki>の形式をとり、xとyは整数または1文字、incrはオプションのインクリメントで整数である。 整数が与えられると、式はxとyの間の各数値に展開される。 各項が同じ幅になるように、整数の前に0を置くことができる。 xまたはyのどちらかが0から始まる場合、シェルは生成されるすべての項に同じ桁数を含ませようとし、必要な場合はゼロパディングを行う。 文字が指定された場合、式はデフォルトのCロケールを使用して、xとyの間で辞書式に各文字に展開される。 xとyは同じ型でなければならないことに注意。 インクリメントを指定すると、各項の差として使用される。 デフォルトの増分は1または-1である。
      characters, and incr, an optional increment, is an integer.  When integers are supplied, the  ex‐
      pression  expands  to  each number between x and y, inclusive.  Supplied integers may be prefixed
      with 0 to force each term to have the same width.  When either x or y begins  with  a  zero,  the
      shell  attempts  to  force all generated terms to contain the same number of digits, zero-padding
      where necessary.  When characters are supplied, the expression expands to each character  lexico‐
      graphically  between x and y, inclusive, using the default C locale.  Note that both x and y must
      be of the same type.  When the increment is supplied, it is used as the difference  between  each
      term.  The default increment is 1 or -1 as appropriate.


      Brace expansion is performed before any other expansions, and any characters special to other ex‐
ブレイス展開は、他の展開の前に実行され、他の展開で特殊な文字は結果に保存される。 これは厳密にテキスト的である。 Bashは、展開の文脈や中括弧間のテキストに構文解釈を適用しない。
      pansions are preserved in the result.  It is strictly textual.  Bash does not apply any syntactic
      interpretation to the context of the expansion or the text between the braces.


      A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least
正しく形成された中括弧展開は、引用符で囲まれていない開中括弧と閉中括弧、そして少なくとも1つの引用符で囲まれていないカンマ、または有効なシーケンス式を含んでいなければならない。 正しく形成されていない中括弧展開は、そのまま残される。 または,は、ブレース表現の一部とみなされないようにバックスラッシュで囲むことができる。 パラメータ展開との衝突を避けるため、文字列${は波括弧展開の対象とはみなされず、 }を閉じるまで波括弧展開を禁止する。
      one unquoted comma or a valid sequence expression.  Any incorrectly  formed  brace  expansion  is
      left  unchanged.  A { or , may be quoted with a backslash to prevent its being considered part of
      a brace expression.  To avoid conflicts with parameter expansion, the string ${ is not considered
      eligible for brace expansion, and inhibits brace expansion until the closing }.


      This  construct is typically used as shorthand when the common prefix of the strings to be gener‐
この構文は、生成する文字列の共通接頭辞が上記の例よりも長い場合に、通常省略記法として使用される:
      ated is longer than in the above example:


              mkdir /usr/local/src/bash/{old,new,dist,bugs}
<code>mkdir /usr/local/src/bash/{old,new,dist,bugs}</code>
      or
or
              chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
<code>chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}</code>


      Brace expansion introduces a slight incompatibility with historical versions of sh.  sh does  not
中括弧の拡張は、歴史的なバージョンのshと若干の非互換性をもたらす。shは、中括弧が単語の一部として現れる場合、開閉中括弧を特別に扱わず、出力に中括弧を保持する。 Bashは、中括弧展開の結果として、単語から中括弧を削除する。 例えば、<nowiki>file{1,2}</nowiki>としてshに入力された単語は、出力では同じように表示される。 同じ単語がbashによって展開された後、file1 file2として出力される。 shと厳密な互換性を保ちたい場合は、bashを+Bオプションで起動するか、setコマンドの+Bオプションで中括弧の展開を無効にする(後述の[[#SHELL BUILTIN COMMANDS|SHELL BUILTIN COMMANDS ]]を参照)。
      treat  opening or closing braces specially when they appear as part of a word, and preserves them
      in the output.  Bash removes braces from words as a consequence of brace expansion.  For example,
      a  word entered to sh as file{1,2} appears identically in the output.  The same word is output as
      file1 file2 after expansion by bash.  If strict compatibility with sh is desired, start bash with
      the +B option or disable brace expansion with the +B option to the set command (see SHELL BUILTIN
      COMMANDS below).


=== Tilde Expansion ===
=== Tilde Expansion ===