Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

copying an array



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