Re: EPIPE in standard utils ([issue41])
[email protected] (Paul Jarc) Tue, 04 Mar 2003 16:59:22 -0500
| Newsgroups | gmane.comp.gnu.utils.bugs,gmane.comp.gnu.textutils.bugs |
|---|---|
| Organization | What did you have in mind? A short, blunt, human pyramid? |
| Message-ID | <[email protected]> |
Tom Lord <[email protected]> wrote: > Exit status of non-leading programs in pipelines is a weak spot of > shell programming. Non-trailing, you mean? > Using the notation "|+" for this, one might write: > > set -e > > sort "$somefile" |+ head -1 > ,first-one > > expecting the script to fail if "$somefile" can not be opened or > the `sort' fails for some other reason. > > But what if `sort' will die of a SIGPIPE? FWIW, it's easy enough to prevent that in the script, by making sure the later programs in the pipeline read stdin all the way to EOF. sort "$somefile" |+ sed -n 1p > ,first-one > Consider that `sort' may get SIGPIPE or EPIPE for two very distinct > reasons. (1) it might get that error because the consumer for its > stdout has stopped reading. This is an ordinary and expected > condition and means only that `sort' is free to exit at will. That would not be true in a situation where the reading end of the pipe is closed as a result of an error, and the error is otherwise not reported - or at least, not sufficently reported. How sure are we that that can never happen? paul