Zsh Mailing List Archive
Messages sorted by:
Re: Is this possible in ZSH?
- X-seq: zsh-users 15546
- From: nix@xxxxxxxxxxxxxxxx
- To: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Is this possible in ZSH?
- Date: Mon, 15 Nov 2010 00:01:05 +0200
- Cc: zsh-users@xxxxxxx
- Importance: Normal
- In-reply-to: <101114121011.ZM28022@xxxxxxxxxxxxxxxxxxxxxx>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <f15da59a0d6892172fc4c8f15cee0c59.squirrel@xxxxxxxxxxxxx> <101114121011.ZM28022@xxxxxxxxxxxxxxxxxxxxxx>
> On Nov 14, 3:12pm, nix@xxxxxxxxxxxxxxxx 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.
> repeat 3 do (let "x /= 2"); print $x; done
> unset x
> zmodload zsh/mapfile
> 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
Thanks for this hint, i try to reproduce something based on your help.
Messages sorted by: