RE-SUMMARY: non-zero exit status

Igor Schein (igor@andrew.air-boston.com)
Tue, 17 Feb 1998 16:50:28 -0500 (EST)

Original posting
-------------------------------------------------------------------------
> Hi, I noticed a very strange thing with csh/tcsh.
>
> % yes|head -1;echo $status
> y
> status=-2147483635
> %
>
> If I use tcsh instead of csh, the status is 141.
>
> But, sh behaves fine:
>
> % sh -e
> $ yes|head -1
> y
> $
>
> The shell doesn't exit, so the return status is zero.
>
> Since yes not in /usr/ucb on Solaris, it can be simulated by
> awk 'BEGIN{while(1)print "y"}'. Also, there's nothing wrong with head
> command, because head can be simulated by awk '{print;exit 0}' with the
> same result.
>
> So I make a conclusion that csh family doesn't like the broken pipe, while
> bourne shell family is ok with it.
>
> This looks like a fairly important porting issue, because sh scripts will
> behave differently ported to csh whenever they test status of previous
> command. Does any1 know more about this issue?
>
> Thanks.
>
> Will summarize if there's interest.
>
> Igor
-------------------------------------------------------------------------

Hello,

I have gathered more info on this subject.

Basically, looks like csh's behavior is correct - take this, csh bashers
:-)

The correct return value for csh and tcsh is 141, and that's what returned
on 5.6. 5.5.1 and 4.1.4 were buggy, returning -2^32 and 2^15
respectively. Basically, broken pipe occures in command line, and the
signal for it is 13, or 0xD. Than 0x80 is padded to indicated
interrupted system call, pipe() in this case. So shell return 0x8D = 141.

Now the question is: why bourne shell family doesn't return error status?

Igor