zsh-users
 help / color / mirror / code / Atom feed
* indirect array element assignment?
@ 2022-07-02 10:33 Anthony Heading
  2022-07-02 18:13 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Anthony Heading @ 2022-07-02 10:33 UTC (permalink / raw)
  To: zsh-users

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?


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-03 16:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-02 10:33 indirect array element assignment? Anthony Heading
2022-07-02 18:13 ` Bart Schaefer
2022-07-02 18:23   ` Bart Schaefer
2022-07-03  2:28   ` Anthony Heading
2022-07-03  3:41     ` Bart Schaefer
2022-07-03 16:43       ` Anthony Heading

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).