zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Peter Stephenson <p.w.stephenson@ntlworld.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: "${*:offset:length}" and ksh93/bash compatibility
Date: Sun, 13 Mar 2022 20:23:19 +0100	[thread overview]
Message-ID: <CAHYJk3Top8+Px7GQKR1vACc3kXsLuo9fimO+qL5xtMN-szKFpQ@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7aa8J9pTcBcTYqkHPx_2Z+GP8oUHXLyJt1FJ2nwsmzwTw@mail.gmail.com>

On 3/13/22, Bart Schaefer <schaefer@brasslantern.com> wrote:
> Arriving to this a bit late, have been traveling.
>
> On Sun, Mar 13, 2022 at 8:22 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>>
>> zsh% a=(one two three); echo "${a[*]:0:2}"
>> on
>> zsh% bash -c 'a=(one two three); echo "${a[*]:0:2}"'
>> one two
>
> The [*] subscript in double quotes has always been treated differently
> in zsh.  You need [@] or the (@) modifier to preserve array-ness.  I'm
> not sure the presence of the :off:len suffix should change that as a
> side-effect, at least not in native zsh mode ... and it might be
> difficult to "notice" the suffix early enough in the expansion code to
> cause that effect anyway.  Particularly without also having the effect
> that the end result is not joined into a single string.

The way it works in bash is it does become a scalar, but the subscript
works on the array elements before joining (just like [1,3] does in
zsh in the same context). I'm reasonably sure that there would be no
difference in the zsh code for handling $*:X or $a[*]:X, other than
having to add the extra faked element for X=0. I think the correct
answer is to always have :off:len work on the array indices if they
exist, regardless of double-quoted-ness... But I also just took a look
at getindex() and don't want to replicate the appropriate parts of
that logic (which would require understanding what any of the parts
do).

I'm also not sure if it matters too much since it's been some years
before anyone even noticed it, I just (somewhat naively) thought that
maybe it wouldn't be too difficult to add...

-- 
Mikael Magnusson


  reply	other threads:[~2022-03-13 19:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10  7:50 Stephane Chazelas
2022-03-10 12:48 ` Mikael Magnusson
2022-03-10 14:25   ` Peter Stephenson
2022-03-13 15:22     ` Mikael Magnusson
2022-03-13 18:21       ` Bart Schaefer
2022-03-13 19:23         ` Mikael Magnusson [this message]
2022-03-13 20:57           ` Bart Schaefer
2022-03-16  5:57       ` Jun T
2022-03-16 15:57         ` Mikael Magnusson
2022-03-23  8:08         ` Jun T
2022-03-23 10:23           ` Mikael Magnusson

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=CAHYJk3Top8+Px7GQKR1vACc3kXsLuo9fimO+qL5xtMN-szKFpQ@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=p.w.stephenson@ntlworld.com \
    --cc=schaefer@brasslantern.com \
    --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).