Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh job control



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