/usr/bin/bash: Difference between revisions

Line 750: Line 750:


=== Command Substitution ===
=== Command Substitution ===
      Command  substitution  allows the output of a command to replace the command name.  There are two
Command  substitution  allows the output of a command to replace the command name.  There are two forms:
      forms:


              $(command)
<code>$(command)</code>
      or
              `command`


      Bash performs the expansion by executing command in a subshell environment and replacing the com‐
or
      mand  substitution  with  the standard output of the command, with any trailing newlines deleted.
      Embedded newlines are not deleted, but they may be removed during word  splitting.  The  command
      substitution $(cat file) can be replaced by the equivalent but faster $(< file).


      When  the old-style backquote form of substitution is used, backslash retains its literal meaning
<code>`command`</code>
      except when followed by $, `, or \.  The first backquote not preceded by a  backslash  terminates
      the command substitution.  When using the $(command) form, all characters between the parentheses
      make up the command; none are treated specially.


      Command substitutions may be nested. To nest when using the backquoted form,  escape  the  inner
Bashは、サブシェル環境でコマンドを実行し、コマンドの置換を、末尾の改行が削除されたコマンドの標準出力に置き換えることで、展開を行う。
      backquotes with backslashes.
埋め込まれた改行は削除されないが、単語分割の際に削除されることがある。 コマンド置換<nowiki>$(cat file)</nowiki>は、同等だがより高速な<nowiki>$(< file)</nowiki>で置き換えることができる。


      If  the  substitution appears within double quotes, word splitting and pathname expansion are not
旧式のバッククォート形式の置換を使用する場合、バックスラッシュは、<nowiki>$、`、 \</nowiki>の後に続く場合を除き、リテラルな意味を保持する。 バックスラッシュが先行しない最初のバッククォートは、コマンド置換を終了する。 (command)形式を使用する場合、括弧の間のすべての文字がコマンドを構成する。
      performed on the results.
 
コマンド置換は入れ子にすることができる。 バッククォート形式を使用しているときに入れ子にするには、バッククォート内をバックスラッシュでエスケープする。
 
置換が二重引用符で囲まれている場合、単語分割とパス名展開は行われない。


=== Arithmetic Expansion ===
=== Arithmetic Expansion ===