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

Re: nested parameter expansion



> On 24 September 2020 at 09:03 jdh <dhenman@xxxxxxxxx> wrote:
> I can't get, what should be simple nested parameter to work.
> I think that $ndx needs to be expanded before the letter P before it 1st.
> 
> Simple example:
> 
>     ndx=1
>     P1_ARRAY=("1" "2" "3")
>     
>     print ${P${ndx}_ARRAY}
> #results in: "zsh bad substitution

I don't think there's a simple way to do it without an extra intermediate
variable:

var="P${ndx}_ARRAY"
print ${(P)var}

You could add some eval trickery, but I suspect it's not worth making it any
more complicated.

pws




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