Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh job control
- X-seq: zsh-users 4692
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: <frank@xxxxxxxxxxxxxxxxxxxxxx>
- Subject: Re: zsh job control
- Date: Mon, 25 Feb 2002 11:41:10 -0800 (PST)
- Cc: <zsh-users@xxxxxxxxxx>
- In-reply-to: <Pine.LNX.3.96.1020225134642.30105A-100000@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Sender: <schaefer@xxxxxxxxxxxxxxxx>
On Mon, 25 Feb 2002 frank@xxxxxxxxxxxxxxxxxxxxxx wrote:
> What I am looking for is an integration of the control forms like while,
> for, etc with job control.
There was a similar discussion a couple of years ago:
http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=2676
(Hey, Geoff: When you use a redirect link like the one above, the
followups and references links at the bottom of the archive message
are broken.)
> What I am hoping is that there is some sort of job control associated with
> the standard zsh loops:
No, there's no magic syntax for this built in. You just have to make use
of the existing job control tools.
If you're not worried about always having exactly N jobs running, you can
do something simple like this:
N=4
pids=()
for file in **/*.gz
do
zcat $file | fgrep foobar &
pids=($pids $!)
if (( $#pids >= N )); then wait $pids[N]; pids=(); fi
done > results.txt
This starts four jobs and then waits for the fourth one to finish before
starting four more. You could use "wait" with no arguments to wait for
all four jobs to finish, but that would also wait for any other background
jobs that might have been started outside the loop.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author