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

indirect array element assignment?



What's the best zsh way of doing an indirect array element assignment?   This works quite nicely in bash: 

#!/bin/bash 
fruits=("apple" "banana" "carrot")
# but a carrot is not a fruit
var="fruits"
declare -n v=$var
v[2]="cherry"
echo ${fruits[@]}
=> apple banana cherry

Everything in zsh I've tried around  ${${(P)v}[2]::=cherry}  with misc different bracketing gets "not an identifier", suggesting maybe the ::= form doesn't support subscripting.   Is there something better than 'eval' for this?




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