zsh-users
 help / color / mirror / code / Atom feed
* copying an array
@ 2014-08-05  5:44 Dominik Vogt
  2014-08-05 15:41 ` Yuya Amemiya
  2014-08-05 15:55 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Dominik Vogt @ 2014-08-05  5:44 UTC (permalink / raw)
  To: Zsh Users

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 ^_^  ^_^



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-08  6:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-05  5:44 copying an array Dominik Vogt
2014-08-05 15:41 ` Yuya Amemiya
2014-08-05 15:55 ` Bart Schaefer
2014-08-08  5:12   ` Dominik Vogt
2014-08-08  6:07     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).