/usr/bin/bash: Difference between revisions

Line 130: Line 130:


===Pipelines ===
===Pipelines ===
      A  pipeline  is a sequence of one or more commands separated by one of the control operators | or
パイプラインは、制御演算子|または|&で区切られた1つまたは複数のコマンドのシーケンスである。 パイプラインの書式は以下の通りである:
      |&.  The format for a pipeline is:


:<code>[time [-p]] [ ! ] command [ [|⎪|&] command2 ... ]</code>
:<code>[time [-p]] [ ! ] command [ [|⎪|&] command2 ... ]</code>


      The standard output of command is connected via a pipe to the standard input of  command2.  This
commandの標準出力は、パイプを経由してcommand2の標準入力に接続される。 この接続は、コマンドで指定されたリダイレクション(後述の'''[[#REDIRECTION|REDIRECTION]]'''を参照)の前に実行される。
      connection is performed before any redirections specified by the command (see REDIRECTION below).
もし|&が使われると、commandの標準出力に加えて、commandの標準エラーもパイプを通してcommand2の標準入力に接続される。 この標準エラーから標準出力への暗黙のリダイレクトは、コマンドによって指定されたリダイレクトの後に実行される。
      If |& is used, command's standard error, in addition to its standard output, is connected to com‐
      mand2's  standard  input through the pipe; it is shorthand for 2>&1 |.  This implicit redirection
      of the standard error to the standard output is performed after any redirections specified by the
      command.


      The  return  status of a pipeline is the exit status of the last command, unless the pipefail op‐
パイプラインの戻りステータスは、pipefailオプションが有効になっていない限り、最後のコマンドの終了ステータスになる。 pipefailが有効な場合、パイプラインの戻りステータスは、0以外のステータスで終了した最後の(右端の)コマンドの値、またはすべてのコマンドが正常に終了した場合は0になる。
      tion is enabled.  If pipefail is enabled, the pipeline's return status is the value of  the  last
パイプラインの前に予約語 ! がある場合、そのパイプラインの終了ステータスは、前述の終了ステータスの論理的否定となる。 シェルは、値を返す前にパイプラインのすべてのコマンドが終了するのを待つ。
      (rightmost)  command  to  exit with a non-zero status, or zero if all commands exit successfully.
      If the reserved word ! precedes a pipeline, the exit status of  that  pipeline  is  the  logical
      negation of the exit status as described above.  The shell waits for all commands in the pipeline
      to terminate before returning a value.


      If the time reserved word precedes a pipeline, the elapsed as well as user and system  time  con‐
時間予約語がパイプラインの前にある場合、パイプラインが終了すると、その実行によって消費されたユーザー時間とシステム時間だけでなく、経過時間も報告される。 pオプションは、出力フォーマットをPOSIXで指定されたものに変更する。 シェルがposixモードの場合、次のトークンが `-' で始まっていると、timeを予約語として認識しない。 TIMEFORMAT変数には、タイミング情報をどのように表示するかを指定する書式文字列を設定することができる。
      sumed by its execution are reported when the pipeline terminates.  The -p option changes the out‐
      put format to that specified by POSIX.  When the shell is in posix mode, it  does  not  recognize
      time  as a reserved word if the next token begins with a `-'.  The TIMEFORMAT variable may be set
      to a format string that specifies how the timing information should be  displayed;  see  the  de‐
      scription of TIMEFORMAT under Shell Variables below.


      When the shell is in posix mode, time may be followed by a newline.  In this case, the shell dis‐
シェルがposixモードの場合、timeの後に改行が続くことがある。 この場合、シェルはシェルとその子シェルが消費したユーザー時間とシステム時間の合計を表示する。 TIMEFORMAT 変数を使用して、時間情報の書式を指定することができる。
      plays the total user and system time consumed by the shell  and  its  children.  The TIMEFORMAT
      variable may be used to specify the format of the time information.


      Each  command in a pipeline is executed as a separate process (i.e., in a subshell).  See COMMAND
パイプラインの各コマンドは、別々のプロセスとして(つまりサブシェルで)実行される。 サブシェル環境の説明については、'''[[#COMMAND EXECUTION ENVIRONMENT|COMMAND EXECUTION ENVIRONMENT]]'''を参照のこと。 shopt 組み込み関数を使用して lastpipe オプションを有効にすると (後述の shopt の説明を参照)、パイプラインの最後の要素をシェルプロセスで実行することができる。
      EXECUTION ENVIRONMENT for a description of a subshell environment.  If the lastpipe option is en‐
      abled  using  the shopt builtin (see the description of shopt below), the last element of a pipe‐
      line may be run by the shell process.


=== Lists ===
=== Lists ===