From Bash Reference Manual
A pipeline is a sequence of simple commands separated by one of the control operators
|
or|&
.
From POSIX 2013
A pipeline is a sequence of one or more commands separated by the control operator
|
.
I know that Bash has many extensions to POSIX shells, e.g. |&
.
But are the component commands of a pipeline
- simple commands or
- just any commands (simple, pipeline again, list, compound, and function)?
In Bash, the following works
$ for f in $(ls *); do echo $f; done | cat
but the first component command of the pipeline isn't simple but compound.
2 Answers 2
The manual for Bash 4.4.5 does not contain the word "simple" from the description of what a pipeline is made up of. The "simple command" you're referring to was probably either a typo or an oversight, or possibly a leftover from a long time ago.
It was fixed by the bash
maintainer in April 2014, and it currently reads:
A pipeline is a sequence of one or more commands separated by one of the control operators
|
or|&
.
A pipeline can clearly be made up from commands that or not simple commands (for example subshells and for
loops, which are compound commands).
-
1Fixed in the 2014年03月21日 snapshotStéphane Chazelas– Stéphane Chazelas2018年02月18日 07:18:59 +00:00Commented Feb 18, 2018 at 7:18
Bash manual (man bash
) has never included the word simple in the description of a pipeline. Get any of the bash-${version}.tar.gz
files from this site, decompress and take a look at the file bash-${version}/doc/bash.1
which is the manual of bash for each version.
What has included the word simple
is the bashref
file. From the same downloaded and expanded file as above, read bash-${version}/doc/bashref.pdf
, which has included the word simple
at point 3.2.2 Pipelines
up to version 4.3 of the said bashref manual.
3.2.2 Pipelines A pipeline is a sequence of simple commands separated by ... ‘|’ or ‘|&’.
That the bashref included such word has never meant that complex commands (as opposed to "simple") were in any way excluded from being used as part of a pipeline (including {...}
if...then...
while...do...
and others).
Such wording is a simple typo and should not be used to extract any conclusion.
echo
is a built-in command of bash, but there is also/bin/echo
that does almost exactly the same thingls *
, I tried to edit, but it wouldn't let me make such a minor edit. Needed more characters. Put 5 spaces in front of that line, which marks up as 'code', then you can add the backticks