zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: namerefs to var[idx]
Date: Fri, 8 Mar 2024 13:23:07 +0000	[thread overview]
Message-ID: <20240308132307.xvc3mh4uo67wvr4x@chazelas.org> (raw)

$ f() { typeset -nu v=$1; echo ${v[1]}; }
$ a=abcd
$ f 'a[2,3]'
b

OK but:

$ f() { typeset -nu v=$1; echo $v[1]; }
$ f 'a[2,3]'
f: no matches found: bc[1]

It's amazing that these actually work:

$ f() { typeset -nu v=$1; v[1]=foo; }
$ f a
$ echo $a
foo2345
$ f 'a[6]'
$ echo $a
foo23foo5

This one not really:

$ a=12345
$ f 'a[2,3]'
$ echo $a
1foo45

In that one could expect the first character of the "23"
substring to be changed to "foo", but I can see that's asking
quite a lot.

-- 
Stephane


             reply	other threads:[~2024-03-08 13:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 13:23 Stephane Chazelas [this message]
2024-03-08 18:30 ` Bart Schaefer

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=20240308132307.xvc3mh4uo67wvr4x@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=zsh-workers@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).