bash: Pipelines

1 
1 3.2.2 Pipelines
1 ---------------
1 
1 A 'pipeline' is a sequence of one or more commands separated by one of
1 the control operators '|' or '|&'.
1 
1    The format for a pipeline is
1      [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ...
1 
1 The output of each command in the pipeline is connected via a pipe to
1 the input of the next command.  That is, each command reads the previous
1 command's output.  This connection is performed before any redirections
1 specified by the command.
1 
1    If '|&' is used, COMMAND1's standard error, in addition to its
1 standard output, is connected to COMMAND2's standard input through the
1 pipe; it is shorthand for '2>&1 |'.  This implicit redirection of the
1 standard error to the standard output is performed after any
1 redirections specified by the command.
1 
1    The reserved word 'time' causes timing statistics to be printed for
1 the pipeline once it finishes.  The statistics currently consist of
1 elapsed (wall-clock) time and user and system time consumed by the
1 command's execution.  The '-p' option changes the output format to that
11 specified by POSIX.  When the shell is in POSIX mode (⇒Bash POSIX
 Mode), it does not recognize 'time' as a reserved word if the next
1 token begins with a '-'.  The 'TIMEFORMAT' variable may be set to a
1 format string that specifies how the timing information should be
1 displayed.  ⇒Bash Variables, for a description of the available
1 formats.  The use of 'time' as a reserved word permits the timing of
1 shell builtins, shell functions, and pipelines.  An external 'time'
1 command cannot time these easily.
1 
1    When the shell is in POSIX mode (⇒Bash POSIX Mode), 'time' may
1 be followed by a newline.  In this case, the shell displays the total
1 user and system time consumed by the shell and its children.  The
1 'TIMEFORMAT' variable may be used to specify the format of the time
1 information.
1 
1    If the pipeline is not executed asynchronously (⇒Lists), the
1 shell waits for all commands in the pipeline to complete.
1 
11    Each command in a pipeline is executed in its own subshell (⇒
 Command Execution Environment).  The exit status of a pipeline is the
1 exit status of the last command in the pipeline, unless the 'pipefail'
1 option is enabled (⇒The Set Builtin).  If 'pipefail' is enabled,
1 the pipeline's return status is the value of the last (rightmost)
1 command to exit with a non-zero status, or zero if all commands exit
1 successfully.  If the reserved word '!' precedes the pipeline, the exit
1 status is the logical negation of the exit status as described above.
1 The shell waits for all commands in the pipeline to terminate before
1 returning a value.
1