From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9149 invoked by alias); 5 Jul 2014 17:32:43 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18926 Received: (qmail 11809 invoked from network); 5 Jul 2014 17:32:30 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140705103233.ZM12028@torch.brasslantern.com> Date: Sat, 05 Jul 2014 10:32:33 -0700 In-reply-to: <20140705050758.GA3836@solfire> Comments: In reply to meino.cramer@gmx.de "wait()ing for a job" (Jul 5, 7:07am) References: <20140705050758.GA3836@solfire> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: wait()ing for a job MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jul 5, 7:07am, meino.cramer@gmx.de wrote: } } I want to write a zsh-script to start several rsync-jobs in background } and 'wait' for each of them to end. I need the return code of each } of them. [...] } I need all return codes -- if one rsync fails, I got a problem. } } What is it, what I don't correctly understand from the manpage -- what } does wait according to the return codes of several jobs? Unfortunately you can't accomplish what you need with only "&" and "wait". The wait builtin always returns the status for exactly one job, either the first one among those you specified as the arguments, or the last one out of all possible jobs. If several jobs exit "too close together" then the return status from some of them may be lost, because the shell will handle them asynchronously while "wait" is not active. See e.g. comments in Functions/Misc/zargs relating to the --max-procs option. One way to achieve what you want is to wrap each rsync job in a subshell which finishes with "print $?". This will cause the subshell to block until something reads its output, so that you can be sure of associating the correct exit status with each rsync. If you combine this with the "... {var}>&1" syntax, you can dynamically assign descriptor numbers to each subshell and either monitor them with "zselect" or poll them with "read -t 0 <&$var". I don't have time right now to write up an example of this but I may be able to do so later if you can't work it out.