bug-textutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EPIPE in standard utils ([issue41])


From: Paul Jarc
Subject: Re: EPIPE in standard utils ([issue41])
Date: Tue, 04 Mar 2003 16:59:22 -0500
User-agent: Gnus/5.090015 (Oort Gnus v0.15) Emacs/21.2 (i686-pc-linux-gnu)

Tom Lord <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]