From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3877 invoked by alias); 14 Nov 2010 20:10:37 -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: 15544 Received: (qmail 15171 invoked from network); 14 Nov 2010 20:10:35 -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,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <101114121011.ZM28022@torch.brasslantern.com> Date: Sun, 14 Nov 2010 12:10:11 -0800 In-reply-to: Comments: In reply to nix@myproxylists.com "Is this possible in ZSH?" (Nov 14, 3:12pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Is this possible in ZSH? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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.