help / color / mirror / code / Atom feed
From: Philippe Altherr <philippe.altherr@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Subscript flag (i) not working correctly on empty strings?
Date: Fri, 6 Jan 2023 17:01:37 +0100	[thread overview]
Message-ID: <CAGdYchuqW79Q3nMguaOrJKEcRwMnQgDRNhHmh3hF5V6sgp=q4g@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

The following script

s=aaa; echo $s[(i)z];
> s=aa; echo $s[(i)z];
> s=a; echo $s[(i)z];

s=; echo $s[(i)z];

prints this

> 3
> 2
> 0

Why is the last line 0 and not 1? The documentation of (i) and (r) states
that if the pattern isn't found in the string, the length of the string
plus 1 is returned. I can't find anything that would explain the 0.

For arrays, (i) behaves as expected. The following script

a=(a a a); echo $a[(i)z];
> a=(a a); echo $a[(i)z];
> a=(a); echo $a[(i)z];

a=(); echo $a[(i)z];

prints this

> 3
> 2
> 1

Is the empty string behavior a bug or an (undocumented?) feature?


[-- Attachment #2: Type: text/html, Size: 1710 bytes --]

             reply	other threads:[~2023-01-06 16:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 16:01 Philippe Altherr [this message]
2023-01-06 17:23 ` Peter Stephenson
2023-01-06 18:12   ` Bart Schaefer
2023-01-07 13:45     ` Philippe Altherr
2023-01-07 13:52       ` Roman Perepelitsa
2023-01-07 13:54         ` Roman Perepelitsa
2023-01-08 19:47     ` Peter Stephenson

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGdYchuqW79Q3nMguaOrJKEcRwMnQgDRNhHmh3hF5V6sgp=q4g@mail.gmail.com' \
    --to=philippe.altherr@gmail.com \
    --cc=zsh-workers@zsh.org \


* 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


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).