- publishing free software manuals
GNU Bash Reference Manual
by Chet Ramey and Brian Fox
Paperback (6"x9"), 180 pages
ISBN 0954161777
RRP £19.95 ($29.95)

"An essential resource .... the most detailed coverage available for all aspects of Bash" --- Linux User and Developer Magazine (Issue 37, Mar 2004) Get a printed copy>>>

3.2.2 Pipelines

A pipeline is a sequence of simple commands separated by ‘|’.

The format for a pipeline is

[time [-p]] [!] command1 [| 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.

The reserved word time causes timing statistics to be printed 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. The TIMEFORMAT variable may be set to a format string that specifies how the timing information should be displayed. See section 5.2 Bash Variables, for a description of the available formats. The use of time as a reserved word permits the timing of shell builtins, shell functions, and pipelines. An external time command cannot time these easily.

If the pipeline is not executed asynchronously (see section 3.2.3 Lists of Commands), the shell waits for all commands in the pipeline to complete.

Each command in a pipeline is executed in its own subshell (see section 3.7.3 Command Execution Environment). The exit status of a pipeline is the exit status of the last command in the pipeline, unless the pipefail option is enabled (see section 4.3 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. The shell waits for all commands in the pipeline to terminate before returning a value.

ISBN 0954161777GNU Bash Reference ManualSee the print edition