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

Re: zoptargs usage to place multiple values into an array



On Wed, Sep 28, 2022 at 3:01 PM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>
> I know this is in the documentation, but what is the incantation to
> zoptargs to permit multiple command line **values**?

You mean zparseopts?  OPTARG is a variable used by the getopts builtin.

> Desired CLI:
>
>         $ ./script.zsh --arg value1 --arg value2 --arg value3
>
> Desired effect in script:
>
>         declare -a arg=( value1 value2 value3 )

You can't get that directly. If you use

zparseopts - -arg+:=arg

Then you get

arg=(--arg value1 --arg value2 --arg value3)

from which you have to delete the "--arg" elements yourself, e.g.

arg=(${arg:#--arg})

Is that close enough?




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