From: "Anthony Heading" <ajrh@ajrh.net>
To: zsh-users@zsh.org
Subject: indirect array element assignment?
Date: Sat, 02 Jul 2022 06:33:40 -0400 [thread overview]
Message-ID: <11ca04c9-1503-4cd2-a44b-635dc53e43a8@www.fastmail.com> (raw)
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?
next reply other threads:[~2022-07-02 10:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-02 10:33 Anthony Heading [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11ca04c9-1503-4cd2-a44b-635dc53e43a8@www.fastmail.com \
--to=ajrh@ajrh.net \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).