Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: "${*:offset:length}" and ksh93/bash compatibility
On 3/10/22, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> On 10 March 2022 at 12:48 Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> On 3/10/22, Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>> > Should zsh align with bash/ksh there.
>>
>> If we do, it would probably look something like this (does not handle
>> all cases), unless someone has a better idea...
>
> I think it should change --- the documentation is already clear this is
> here to please users of other shells, not native zsh. Otherwise we end
> up with what's (as we say where I come from) neither nowt nor something.
>
> This syntax gives effects similar to parameter subscripting in the
> form
> $name[start,end], but is compatible with other shells; note that both
> off‐
> set and length are interpreted differently from the components of a
> sub‐
> script.
I realized that this is not limited to $*,
zsh% a=(one two three); echo "${a[@]:0:2}"
one two
zsh% a=(one two three); echo "${a[*]:0:2}"
on
zsh% bash -c 'a=(one two three); echo "${a[@]:0:2}"'
one two
zsh% bash -c 'a=(one two three); echo "${a[*]:0:2}"'
one two
So perhaps this should be attacked in a different place/way than my
test patch (though i think the horrible offset hack is still needed
for $*:0 specifically (and i actually didn't even handle that in the
patch anyway.).)
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author