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

Re: clone an associative array?



Marc Chantreux wrote:
> hello all,
> 
> i don't know what i missed in 'parameters expansions' manual but i'm
> unable to clone an associative array :
> 
> % typeset -A homemade
> % homemade=( tm myself c 2005 )
> % echo $homemade[tm]
> myself
> 
> % typeset -A counterfeit
> % counterfeit=${homemade}

As it's a sort of array, you need braces.  However, you also need
to copy keys as well as values.  The syntax is:

typeset -A counterfeit
counterfeit=(${(kv)homemade})

Make sure you don't have the option SH_WORD_SPLIT set.  (This is a
classic example of why it's a good idea to get used to doing without it.)

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070




**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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