Why does bash sometimes say `Broken pipe'?

Why does bash sometimes say `Broken pipe'?


If a sequence of commands appears in a pipeline, and one of the
reading commands finishes before the writer has finished, the
writer receives a SIGPIPE signal. Many other shells special-case
SIGPIPE as an exit status in the pipeline and do not report it.
For example, in:

ps -aux | head

`head' can finish before `ps' writes all of its output, and ps
will try to write on a pipe without a reader. In that case, bash
will print `Broken pipe' to stderr when ps is killed by a
SIGPIPE.

You can build a version of bash that will not report SIGPIPE errors
by uncommenting the definition of DONT_REPORT_SIGPIPE in the file
config-top.h.



Home FAQ