Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
kill the LHS command of a pipe once the RHS command terminates
- X-seq: zsh-users 23991
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: kill the LHS command of a pipe once the RHS command terminates
- Date: Fri, 28 Jun 2019 13:04:30 +0200
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
With some commands I pipe the output to a pager, and when quitting
the pager, I want the command to terminate immediately (so that it
doesn't consume more resources) and want the shell prompt back.
Here are examples with "head -n 1" instead of a pager.
* With just a pipe:
zira% { echo foo; sleep 3; echo err >&2 } | head -n 1
foo
[wait for 3 seconds]
err
zira%
The issue is that when "head -n 1" terminates (just after "echo foo"),
the left-hand-side command is still running. Thus it still consumes
resources, and I also have to wait for the shell prompt, which is bad.
* 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.
Does zsh provide a feature to kill the left-hand-side command in a
clean way (without a race condition, without a temporary file...)?
--
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