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

Re: help with dereferencing variables



On Feb 14,  8:12pm, S. Cowles wrote:
} 
} Many thanks; that was the info I was missing. One small aesthetics
} preference following up on your suggestion and I'm away (does not
} preserve newlines in the array element assignments):
}
} eval ${key}\=\( ${(P)val} \)

This is not equivalent to my suggestion nor to your "method 2".  It's
a bit closer to your "method 1".  In the above formulation, ${(P)val}
is expanded _before_ being eval'd.  That means that spaces and quotes
and other shell syntax in the expansion are re-parsed.

Compare:

key=tmp
val=row
row='this is a row that may );( print oops in a subshell'
eval ${key}\=\( ${(P)val} \)
print "$tmp"
eval ${key}'=( ${(P)val} )'
print "$tmp"



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