From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21492 invoked by alias); 14 Nov 2010 22:01:20 -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: 15546 Received: (qmail 16410 invoked from network); 14 Nov 2010 22:01:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at myproxylists.com does not designate permitted sender hosts) X-Originating-IP: 127.0.0.1 Message-ID: In-Reply-To: <101114121011.ZM28022@torch.brasslantern.com> References: <101114121011.ZM28022@torch.brasslantern.com> Date: Mon, 15 Nov 2010 00:01:05 +0200 Subject: Re: Is this possible in ZSH? From: nix@myproxylists.com To: "Bart Schaefer" Cc: zsh-users@zsh.org User-Agent: SquirrelMail/1.4.20 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal > On Nov 14, 3:12pm, nix@myproxylists.com wrote: > } > } Is it possible to append background process results to a variable or > } to an array without waiting for that job to finish? > > You're effectively asking whether the shell implements multiprocess > shared memory, because otherwise "process results" are only available > as either pipe I/O or as the exit status of the job. The short answer > is no, you can't declare a shell variable that shares writable memory > with a forked child. > > There are several alternatives to simulate the effect you want. You > can use either coprocesses (several examples are in the mailing list > archives, search for "coproc") or the zsh/net/socket module to set up > multiple simultaneous connections from background jobs to the shell. > You can use a trap on SIGCHLD or a loop on zselect (the zsh/zselect > module) to pick up the data as the jobs exit. > > Or you can use the zsh/mapfile module to simulate a shared variable. > Compare: > > x=32 > repeat 3 do (let "x /= 2"); print $x; done > unset x > > zmodload zsh/mapfile > mapfile[shared]=32 > repeat 3 do (let "mapfile[shared] /= 2"); print $mapfile[shared]; done > unset 'mapfile[shared]' > > Just be sure the name you use in place of "shared" is something unique, > because you will destroy the contents of any file in $PWD that has that > name. > Thanks for this hint, i try to reproduce something based on your help.