Re: How to get bash to shut up about SIGPIPE?
From: Paul Jackson <hidden>
Date: 2016-06-15 22:41:56
Could you elaborate on how exactly is it supposed to help?
The key code is in bash/jobs.c.
If you have a bash while or for loop feeding a pipe that shuts down
while the loop is still running commands that try to write the pipe
(perhaps you were pipe'ing to "head -1", and it exit'd, having read its
one line), then the next command to attempt to write that pipe will die,
and the bash instance that is handling that loop (and forked that
command that just died) will notice the command died with a SIGPIPE
signal.
At this point, one of three possible things happens:
1) If your bash is compiled with DONT_REPORT_SIGPIPE defined, then
that bash instance quietly leaves. The concensus around here
is that is "good(tm)."
2) If not so compiled, then:
2a) If you set a trap on SIGPIPE in that shell, it prints:
fprintf (stderr, "%s", j_strsignal (termsig));
2b) Else if you did not trap SIGPIPE, it prints:
fprintf (stderr, "%s: line %d: ", get_name_for_error (),
(line_number == 0) ? 1 : line_number);
pretty_print_job (job, JLIST_NONINTERACTIVE, stderr);
The pretty_print_job() in (2b) can be a multi-line confusion.
Sample output for (2a):
Broken pipe
Sample output in simple one line case for (2b):
foo: line 2: 11663 Broken pipe cat /etc/termcap
A couple of others are reporting different behaviour than what I report
above - including Linus.
So it is almost certain that I don't understand all I know about this.
What behaviour do you see?
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson [off-list ref] 1.650.933.1373, 1.925.600.0401