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-28 13:04:30 +0200, Vincent Lefevre wrote:
> * With a process substitution:
> 
> zira% head -n 1 <(echo foo; sleep 3; echo err >&2)
> foo
> zira%
> 
> Here I get the shell prompt back immediately, which is good. But
> the left-hand-side command is still running, so that it still
> consumes resources; moreover, after the 3 seconds, I get
> 
> zira% err
> 
> In practice, one may want to redirect stderr to the pager too (not
> always, though); this avoids this second issue, but not the first one,
> which is that the left-hand-side command still consumes resources.

There's another issue, but that's a bug in "less": If one uses the
less -c option (in addition to -f, needed with process substitution),
Ctrl-C no longer has any effect: one cannot interrupt the command to
go back to the shell. Example:

zira% less -fc <(echo foo; sleep 3; echo err >&2)

(tested under Debian/unstable).

And I've noticed that zsh doesn't react to Ctrl-C either in the
following case:

zira% { echo foo; sleep 3; echo err >&2 } | { head -n 1 }

while Ctrl-C terminates the pipeline as expected with

zira% { echo foo; sleep 3; echo err >&2 } | head -n 1

With

zira% { echo foo; sleep 3; echo bar; sleep 3; echo err >&2 } | { head -n 2 }

I can terminate the pipeline during the first "sleep 3" (i.e. while
"head -n 2" is still running), but not during the second "sleep 3"
(i.e. once "head -n 2" has terminated).

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