Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: kill the LHS command of a pipe once the RHS command terminates



On 2019-07-07 01:49:19 +0200, Vincent Lefevre wrote:
> Actually I suppose that Ctrl-C kills the subshell, and the pager
> as a consequence. And if I use the following,
> 
> page-and-kill() (trap '' INT; "$@" | { trap - INT; less; kill 0; })
> 
> the "kill 0" no longer kills the command. This can be seen with:
> 
> (trap '' INT; { echo foo; sleep 10; } | { trap - INT; less; kill 0; })
> 
> after typing Ctrl-C in "less", then q to quit. I've noticed that
> dash and mksh have the same issue, but neither bash, nor ksh93.

Actually a better example should be:

  (trap '' INT; sleep 10 | { trap - INT; less; echo foo; kill 0; })

If I wait for 10 seconds, then type 'q' in less, I get:

zira% (trap '' INT; sleep 10 | { trap - INT; less; echo foo; kill 0; })
foo
zsh: terminated  ( trap '' INT; sleep 10 | { trap - INT; less; echo foo; kill 0; }; )
zira% 

But if I type Ctrl-C then 'q' in less, the "sleep 10" is still
running, and I get after the 10 seconds:

zira% (trap '' INT; sleep 10 | { trap - INT; less; echo foo; kill 0; })
zira% 

i.e. no "foo" output and no "zsh: killed" line, i.e. after the Ctrl-C
in less, zsh terminated the right-hand side. I suppose that this is
due to WUE, and both bash and ksh93 do not have this issue as they
implement WCE.

It seems that putting "trap - INT; less;" in a subshell does the work.
However, I get annoying messages:

zira% (trap '' INT; svn log | { (trap - INT; less;); kill 0; })
svn: E000004: Write error: Interrupted system call
zsh: terminated  ( trap '' INT; svn log | { ( trap - INT; less; ); kill 0; }; )

With "kill -9", this is a bit better:

zira% (trap '' INT; svn log | { (trap - INT; less;); kill -9 0; })
zsh: killed     ( trap '' INT; svn log | { ( trap - INT; less; ); kill -9 0; }; )

But I would like to get rid of this message.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author