Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "${*:offset:length}" and ksh93/bash compatibility



On 3/16/22, Jun T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
>> 2022/03/14 0:22, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>>
>> 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
>
> The following patch seems to work for
>  "${*:1:2}"   "${@:1:2}"  "$a[@]:0:2}"  "${a[*]:0:2}"
>
> For example (with or without KSH_ARRAYS):
>
> zsh% printf '<%s>\n' "${a[@]:0:2}"
> <one>
> <two>
>
> If KSH_ARRAYS is not set, "$a:0:2" behaves like "${a[*]:0:2}".
>
> I don't know if there are better/simpler solutions.
> 'make check' passes, but please do some tests to see if there
> are any bad side effects.

It's certainly a lot simpler than my idea, and also seems to work in
the cases I could come up with. I guess if KSH_ARRAYS is not set, then
there is no expectation of bash compatibility anyway so whatever we do
there is fine.

-- 
Mikael Magnusson




Messages sorted by: Reverse Date, Date, Thread, Author