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

Re: copying an array



On Tue, Aug 05, 2014 at 08:55:27AM -0700, Bart Schaefer wrote:
> On Aug 5,  6:44am, Dominik Vogt wrote:
> >
> > typeset -g -a G
> > G=("a b c" d e)
> > copy_array () {
> > 	typeset -g -a "$1"
> > 	# how can this be done?
> > 	$1="($G[@])"
> > }
> 
> You probably don't need the function at all if this is the only thing it
> is doing:
> 
> 	set -A "$1" "$G[@]"

Ah, I did not have "set" on the radar.  Thanks!

> The only reason for the "typeset -g" would be if there is a local array
> in scope whose name is the same as the value of $1.  Otherwise "set -A"
> will create the global array for you.

Is there a specific reason why typeset cannot initialize arrays?

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany



Messages sorted by: Reverse Date, Date, Thread, Author