Charles Smith <cts.priv...@yahoo.com> writes:

> Hi, I have the following script, which just kills itself.
> It sets a trap, but only takes it if the output is not redirected.

It does take it, but the output goes nowhere.

> Can anybody explain to me why?

You are killing the whole process group, which includes both sides of
the pipeline.

> When I run it with stdio redirection, the script is terminated at the kill:
>
>   $ bash -x  test17  2>&1 | tee 0312-29.out
>   + trap 'echo caught signal 2' 2
>   + trap -p
>   trap -- 'echo caught signal 2' SIGINT
>   + grep 8714
>   + ps -eo pid,pgid,cmd
>    8714  8714 bash -x test17
>    8715  8714 tee 0312-29.out
>    8716  8714 ps -eo pid,pgid,cmd
>    8717  8714 grep 8714

These are all the processes you will kill next.

> $ echo $?
> 130

This is the exit code of the tee process, which died of signal 2 before
it could receive the rest of the output through the pipe.  If you don't
redirect stderr you will see what the shell executed after the pipe was
broken.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

Reply via email to