/usr/bin/bash: Difference between revisions

Line 254: Line 254:


== QUOTING ==
== QUOTING ==
      Quoting is used to remove the special meaning of certain characters or words to the shell.  Quot‐
クオートは、シェルに対して特定の文字や単語の特別な意味を取り除くために使用される。 引用符で囲むことで、特殊文字に対する特別な扱いを無効にしたり、予約語をそのようなものとして認識させないようにしたり、パラメータの展開を防止したりすることができる。
      ing can be used to disable special treatment for special characters, to  prevent  reserved  words
      from being recognized as such, and to prevent parameter expansion.


      Each  of  the  metacharacters listed above under DEFINITIONS has special meaning to the shell and
上記の[[#DEFINITIONS|DEFINITIONS]]に列挙されているメタキャラクタは、シェルにとって特別な意味を持ち、それ自身を表す場合にはクォートしなければならない。
      must be quoted if it is to represent itself.


      When the command history expansion facilities are being used (see HISTORY EXPANSION  below),  the
コマンドのヒストリ展開機能を使用する場合(下記の「ヒストリ展開」を参照)、ヒストリ展開を防ぐために、ヒストリ展開文字(通常は「!」)を引用符で囲む必要がある。
      history expansion character, usually !, must be quoted to prevent history expansion.


      There are three quoting mechanisms: the escape character, single quotes, and double quotes.
エスケープ文字、一重引用符、二重引用符である。


      A  non-quoted  backslash (\) is the escape character.  It preserves the literal value of the next
引用符で囲まないバックスラッシュ( \ )はエスケープ文字である。 これは、<改行>を除き、次に続く文字のリテラル値を保持する。 <newline>のペアが現れ、バックスラッシュ自体が引用符で囲まれていない場合、その<newline>は行の続きとして扱われる(つまり、入力ストリームから取り除かれ、事実上無視される)。
      character that follows, with the exception of <newline>.  If a \<newline> pair appears,  and  the
      backslash  is not itself quoted, the \<newline> is treated as a line continuation (that is, it is
      removed from the input stream and effectively ignored).


      Enclosing characters in single quotes preserves the literal value of each  character  within  the
文字を一重引用符で囲むと、引用符内の各文字のリテラル値が保持される。 バックスラッシュが先行する場合でも、一重引用符の間に一重引用符を置くことはできない。
      quotes.  A single quote may not occur between single quotes, even when preceded by a backslash.


      Enclosing  characters  in  double quotes preserves the literal value of all characters within the
二重引用符で文字を囲むと、引用符内のすべての文字のリテラル値が保持されるが、$`\、およびヒストリ展開が有効な場合はシェルがposixモードの場合、! はヒストリ展開が有効になっていても、二重引用符の中では特別な意味を持たない。 文字$`は、二重引用符内でも特別な意味を持つ。 バックスラッシュは、$`", \<改行> のいずれかの文字が続く場合のみ特別な意味を持つ。 二重引用符の前にバックスラッシュを付けると、二重引用符の中で引用符を付けることができる。 有効にすると、二重引用符の中に現れた ! がバックスラッシュでエスケープされない限り、履歴展開が実行される。 の前のバックスラッシュは削除されない。
      quotes, with the exception of $, `, \, and, when history expansion is enabled, !.  When the shell
      is in posix mode, the ! has no special meaning within double quotes, even when history expansion
      is enabled.  The characters $ and ` retain their special meaning within double quotes.  The back‐
      slash retains its special meaning only when followed by one of the following characters: $, `, ",
      \, or <newline>.  A double quote may be quoted within double quotes by preceding it with a  back‐
      slash.  If  enabled, history expansion will be performed unless an ! appearing in double quotes
      is escaped using a backslash.  The backslash preceding the ! is not removed.


      The special parameters * and @ have special meaning when in double quotes (see PARAMETERS below).
特別なパラメータである*@は、二重引用符で囲むと特別な意味を持つ(下記の[[#PARAMETERS|PARAMETERS]]を参照)。


      Words of the form $'string' are treated specially.  The word expands to string,  with  backslash-
$'string'という形式の単語は特別に扱われる。 この単語は文字列に展開され、バックスラッシュでエスケープされた文字が ANSI C標準の指定に従って置き換えられる。 バックスラッシュ・エスケープ・シーケンスが存在する場合は、以下のようにデコードされる:
      escaped  characters replaced as specified by the ANSI C standard.  Backslash escape sequences, if
:\a    alert (bell)
      present, are decoded as follows:
:\b    backspace
              \a    alert (bell)
:\e
              \b    backspace
:\E    an escape character
              \e
:\f    form feed
              \E    an escape character
:\n    new line
              \f    form feed
:\r    carriage return
              \n    new line
:\t    horizontal tab
              \r    carriage return
:\v    vertical tab
              \t    horizontal tab
:\\    backslash
              \v    vertical tab
:\'    single quote
              \\    backslash
:\"    double quote
              \'    single quote
:\?    question mark
              \"    double quote
:\nnn  8ビットの文字で、その値は8進数nnn(1桁から3桁の8進数)である。
              \?    question mark
:\xHH  値が16進数HH(1桁または2桁の16進数)である8ビット文字
              \nnn  the eight-bit character whose value is the octal value nnn (one to three octal dig‐
:\uHHHH Unicode(ISO/IEC 10646)文字で、その値は16進数値HHHHである。 (1桁から4桁の16進数)
                    its)
:\UHHHHHHHH
              \xHH  the  eight-bit  character  whose  value is the hexadecimal value HH (one or two hex
::ユニコード(ISO/IEC 10646)文字で、その値は16進数値HHHHHHHHHHである。 (1桁から8桁の16進数)
                    digits)
:\cx    a control-x character
              \uHHHH the Unicode (ISO/IEC 10646) character whose value is  the  hexadecimal  value  HHHH
                    (one to four hex digits)
              \UHHHHHHHH
                    the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHHHHHH
                    (one to eight hex digits)
              \cx    a control-x character


      The expanded result is single-quoted, as if the dollar sign had not been present.
展開された結果は、ドル記号がなかったかのように、単一引用符でくくられる。


      A double-quoted string preceded by a dollar sign ($"string") will cause the string to  be  trans‐
二重引用符で囲まれた文字列の前にドル記号 ($"string") を置くと、その文字列は現在のロケールに従って翻訳される。 gettextインフラストラクチャは、'''LC_MESSAGES'''と'''TEXTDOMAIN'''シェル変数を使用して、メッセージカタログの検索と翻訳を実行する。 現在のロケールがCまたはPOSIXの場合、または利用可能な翻訳がない場合、ドル記号は無視される。 文字列が翻訳され置換される場合、置換は二重引用符で囲まれる。
      lated  according  to the current locale.  The gettext infrastructure performs the message catalog
      lookup and translation, using the LC_MESSAGES and TEXTDOMAIN shell variables.  If the current lo‐
      cale  is  C  or POSIX, or if there are no translations available, the dollar sign is ignored.  If
      the string is translated and replaced, the replacement is double-quoted.


== PARAMETERS ==
== PARAMETERS ==