A pipeline is a sequence of one or more commands separated by
one of the control operators ‘|’ or ‘|&’.
The format for a pipeline is
[time [-p]] [!] command1 [ | or |& command2 ] ...
The output of each command in the pipeline is connected via a pipe to the input of the next command. That is, each command reads the previous command’s output. This connection is performed before any redirections specified by command1.
If ‘|&’ is the pipeline operator,
command1’s standard error, in addition to
its standard output, is connected to
command2’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 command1,
consistent with that shorthand.
If the reserved word time precedes the pipeline,
Bash prints timing statistics for the pipeline once it finishes.
The statistics currently consist of elapsed (wall-clock) time and
user and system time consumed by the command’s execution.
The -p option changes the output format to that specified
by POSIX.
When the shell is in POSIX mode (see Bash and POSIX),
it does not recognize time as a reserved word if the next
token begins with a ‘-’.
The value of the TIMEFORMAT variable is a format string that
specifies how the timing information should be displayed.
See Bash Variables, for a description of the available formats.
Providing time as a reserved word permits the timing of
shell builtins, shell functions, and pipelines.
An external time command cannot time these easily.
When the shell is in POSIX mode (see Bash and POSIX),
you can use time by itself as a simple command.
In this case, the shell displays the
total user and system time consumed by the shell and its children.
The TIMEFORMAT variable specifies the format of the time information.
If a pipeline is not executed asynchronously (see Lists of Commands), the shell waits for all commands in the pipeline to complete.
Each command in a multi-command pipeline,
where pipes are created,
is executed in its own subshell, which is a
separate process (see Command Execution Environment).
If the lastpipe option is enabled using the shopt builtin
(see The Shopt Builtin),
and job control is not active,
the last element of a pipeline may be run by the shell process.
The exit
status of a pipeline is the exit status of the last command in the
pipeline, unless the pipefail option is enabled
(see The Set Builtin).
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 the pipeline, the
exit status is the logical negation of the exit status as described
above.
If a pipeline is not executed asynchronously (see Lists of Commands), the
shell waits for all commands in the pipeline to terminate before
returning a value.
The return status of an asynchronous pipeline is 0.