Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
copying an array
- X-seq: zsh-users 19008
- From: Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: copying an array
- Date: Tue, 5 Aug 2014 06:44:34 +0100
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Reply-to: vogt@xxxxxxxxxxxxxxxxxx
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