I reduced my problem to this minimal example:
# This is script myscript
echo $ZSH_VERSION
zparseopts -D vxa:=opt_a vx:=opt_b
echo $1
I'm calling the script with
zsh myscript -vxa xx -vx zz a
I would expect that after processing the options, $1 would output a, but I get
5.8
xx
being printed. Why is this the case?
I am aware about a problem with my script, which is that the option vx is a prefix of vxa, and when I modify the script to
zparseopts -D vxa:=opt_a vxb:=opt_b
and call it accordingly, I indeed get the expected result (a) in the output. So, I can fix my script by just renaming the options so that neither one is a prefix of a different option.
However, I also would like to understand, why I see the xx with my original code. There is no error in the invocation (if I replace the -D by -F, I don't get an error message). I could understand it, if my original script would simply fill the wrong variable (taking vx as an abbreviation for vxa), but I don't understand, why the script silently stops parsing after consuming the -vxa option, but not even picking up the mandatory argument xx. What is going on here, and why?