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 09:17:13 -0700, Bart Schaefer wrote:
> zsh% coproc { echo foo; sleep 3; echo err >&2 }; head -n 1 <&p; kill %+
> [1] 53747
> foo
> zsh%
> [1]  + terminated  { echo foo; sleep 3; echo err >&2; }
> zsh%
> 
> If you're going to kill the right-side with an interrupt or other
> signal, you'll have to arrange to trap that so that the subsequent
> kill isn't also skipped.  Also in practice you want something more
> specific than "kill %+" which could kill the wrong job if you have
> multiple backgrounded jobs and the coproc exits before the kill
> occurs.

Something like that seems to work:

  unsetopt NOTIFY
  coproc ...
  local j="${${$(jobs %+)%%]*}#\[}"
  less -f <&p
  kill %$j

but I would like to get rid of the job status that appear at the end.

-- 
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