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

Re: read/write associative array from/to file



On Tue, Jan 3, 2012 at 1:40 AM, Jérémie Roquet <arkanosis@xxxxxxxxx> wrote:

> echo "myArray=(${(kv)myArray})" >| $db
>

That works if there are no spaces or special characters involved.  You
could change that line to remove the double quotes and add (q) or (q-) to
the expansion, and it would handle those:

typeset -A myArray
myArray=(
foo 1\ is\ the\ loneliest\ number
bar 42\ isn\'t\ really\ the\ ultimate\ answer
)
echo myArray=\(${(kvq-)myArray}\) >/tmp/myArray

typeset -A myArray
source /tmp/myArray
echo ${(q-)myArray[bar]}

..wayne..


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