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

Re: Expand each array element with ${(P)...}



On Tue, Feb 6, 2024 at 7:51 AM Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
>
> I have an array of variable names that I would like to expand to an
> array of these variables' values.

You could use this (requires extended_glob):

  ${names/(#m)*/${(P)MATCH}}

Or this, if you need to retain empty elements:

  "${(@)names/(#m)*/${(P)MATCH}}"

I don't know if there is a better way.

Roman.




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