Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: copying an array
- X-seq: zsh-users 19009
- From: Yuya Amemiya <ghostrevery@xxxxxxxxx>
- To: vogt@xxxxxxxxxxxxxxxxxx
- Subject: Re: copying an array
- Date: Wed, 06 Aug 2014 00:41:17 +0900 (JST)
- Cc: zsh-users@xxxxxxx
- 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==
- In-reply-to: <20140805054434.GA4390@linux.vnet.ibm.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20140805054434.GA4390@linux.vnet.ibm.com>
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 <vogt@xxxxxxxxxxxxxxxxxx>
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 ^_^ ^_^
>
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author