Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
indirect array element assignment?
- X-seq: zsh-users 27859
- From: "Anthony Heading" <ajrh@xxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: indirect array element assignment?
- Date: Sat, 02 Jul 2022 06:33:40 -0400
- Archived-at: <https://zsh.org/users/27859>
- Feedback-id: i6aa94791:Fastmail
- List-id: <zsh-users.zsh.org>
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