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-06-29 16:30:55 +0100, Stephane Chazelas wrote:
> 2019-06-29 03:24:33 +0200, Vincent Lefevre:
> [...]
> > Thus if the left-hand-side process has terminated, this tries to
> > kill a random process!
> [...]
>
> Fair enough.
>
> Then, how about:
>
> page-and-kill() ("$@" | { ${PAGER:-less}; kill -s PIPE 0; })
Unfortunately, this is not usable as a Ctrl-C kills the pager.
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.
--
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