From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22903 invoked by alias); 5 Aug 2014 15:41:32 -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: 19009 Received: (qmail 25246 invoked from network); 5 Aug 2014 15:41:29 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=ek3zbFk6wEq2vS6+OvacKSjO1eL6LNOgR8YOAW/42M4=; b=aGFndVagf4uedw9mAPTo2qLKPS/Hmmj8fykL/0v+mkcF0JHjkB+hvSsCJBso8DAlU6 RenmzVmSdNg0fq9tO96FPmTvbJH2DdsmRzbAoEa+fhLRoUL+HeOl7RM4b2dNEu9qNlOC CEnyyfJlJ1dKY16tcQi2ncNyQJVqUa7Ysg4ngOC1m75PMJtZ81zBMaEBab8DQhN7VK43 OQBf/tuQBTPxldec4cFVM/XZOk7QU6Jww3cULrSrN4pmKG7znB89IrggFhHzFYMR3pZB e01ty7Grv8fZ3rbp+AaUnQ/5DqmO3DYucJE0fd4Bs6SAQBlwcE6VJzXu3u0NdiQTJ3ad kpLQ== X-Received: by 10.70.9.100 with SMTP id y4mr5456700pda.12.1407253286660; Tue, 05 Aug 2014 08:41:26 -0700 (PDT) Date: Wed, 06 Aug 2014 00:41:17 +0900 (JST) Message-Id: <20140806.004117.57555736.ghostrevery@gmail.com> To: vogt@linux.vnet.ibm.com Cc: zsh-users@zsh.org Subject: Re: copying an array From: Yuya Amemiya In-Reply-To: <20140805054434.GA4390@linux.vnet.ibm.com> References: <20140805054434.GA4390@linux.vnet.ibm.com> X-Mailer: Mew version 6.3 on Emacs 23.1 / Mule 6.0 =?iso-2022-jp?B?KBskQjJWOzZOJBsoQik=?= Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, Try this: eval $1'=("${G[@]}")' If the value of $1 is foo, this is substituted with eval foo=("${G[@]}") and evaluate it. regards From: Dominik Vogt Subject: copying an array Date: Tue, 5 Aug 2014 06:44:34 +0100 > I'm trying to write a function that > > * takes the name of a new array variable as its argument, > * creates a global array variable with the given name > * gets a copy of the values of another global array. > > Sketch of the function: > -- > typeset -g -a G > G=("a b c" d e) > copy_array () { > typeset -g -a "$1" > # how can this be done? > $1="($G[@])" > } > -- > > The function needs to handle whitespace (or any special > characters) in the values of G gracefully. The closest I've got so > far is > > eval $(echo "$1=($G[@])") > > But this fails to handle whitespace properly. > > Bonus points if this can be done without eval. :-) > > Any ideas? > > Ciao > > Dominik ^_^ ^_^ > >