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

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



On 3/23/22, Jun T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
>> 2022/03/16 14:57, I wrote:
>>
>> The following patch seems to work for
>> "${*:1:2}"   "${@:1:2}"  "$a[@]:0:2}"  "${a[*]:0:2}"
>
> This is a test for the patch.
>
>
> diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
> index b6b1f2e33..20f731dcb 100644
> --- a/Test/D04parameter.ztst
> +++ b/Test/D04parameter.ztst
> @@ -1693,6 +1693,30 @@
>  >b
>  >c
>
> +   () {
> +     emulate -L sh
> +     local a=( one two three )
> +     printf '<%s><%s>\n' ${a[*]:0:2}
> +     printf '<%s><%s>\n' "${a[*]:0:2}"
> +     printf '<%s><%s>\n' ${a[@]:0:2}
> +     printf '<%s><%s>\n' "${a[@]:0:2}"
> +     printf '<%s><%s>\n' "${a:0:2}"
> +     printf '<%s><%s>\n' ${*:1:2}
> +     printf '<%s><%s>\n' "${*:1:2}"
> +     printf '<%s><%s>\n' ${@:1:2}
> +     printf '<%s><%s>\n' "${@:1:2}"
> +   } one two three
> +0:Bash-style offsets, quoted array
> +><one><two>
> +><one two><>
> +><one><two>
> +><one><two>
> +><on><>
> +><one><two>
> +><one two><>
> +><one><two>
> +><one><two>
> +
>     printf "%n" '[0]'
>  1:Regression test for identifier test
>  ?(eval):1: not an identifier: [0]

I think the test should include
 +     printf '<%s><%s>\n' ${*:0:2}
 +     printf '<%s><%s>\n' "${*:0:2}"
 +     printf '<%s><%s>\n' ${@:0:2}
 +     printf '<%s><%s>\n' "${@:0:2}"
as well, since 0 is handled specially (the horrible offset hack).

-- 
Mikael Magnusson




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