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

Is zsh's 'getopts' correctly implemented?



I ask because zsh doesn't recognize OPTERR=0 to silence warnings; and
because in bash the "silent error reporting" of placing a ? in the named
variable and a : in OPTARG, happens whether or not a leading : appears in
the optstring.  That is, a leading : should be equivalent to OPTERR=0,
and should have no effect other than silencing the diagnostics; the lack
of a : should not affect the settings of the named variable and OPTARG.

If the difference is intentional for some reason, it's no big deal.

However, I think this is a bug:

zsh% getopts a:b -a -x
zsh: not an identifier: -a
zsh% echo $OPTIND
2

I don't think OPTIND should be incremented in this case.  (Bash actually
assigns ? to a variable named "-a", which is even worse.)

Another incompatibility:

zsh% getopts a:b foo -a -x
zsh% echo $foo
a
zsh% echo - $OPTARG
-x

bash% getopts a:b foo -a -x
-bash: illegal option -- x

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"




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