Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
bug in getopts
- X-seq: zsh-users 870
- From: "Christopher T. White" <chris@xxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxxx
- Subject: bug in getopts
- Date: Fri, 23 May 1997 12:45:27 -0700
Dear ZSH users and workers,
Forgive me if this has been addressed previously, but I haven't run into
this particular situation before.
Getops seems to be broken in zsh version 3.1.0. It does not behave as
advertised in the man pages, nor as ksh does (ksh on Solaris 2.5 seems to
work correctly). In a nutshell, getops does not correctly process options
to which there are no arguments. If you move the letters around in the
optstring the behavior changes (that's not supposed to happen). And if you
begin the optstring with options that don't take an argument, the arguments
fail to appear in ${OPTARG}.
The following script (go.zsh) illustrates this:
#!/bin/zsh
print "Number of args: $#"
while getopts b:ac x ; do
print "Here's x: ${x}"
case ${x} in
a)
print "I'm an ${x}"
print "I'm number ${OPTIND}"
print "Here's my arg: ${OPTARG}"
;;
b)
print "I'm a ${x}"
print "I'm number ${OPTIND}"
print "Here's my arg: ${OPTARG}"
;;
c)
print "I'm a ${x}"
print "I'm number ${OPTIND}"
print "Here's my arg: ${OPTARG}"
;;
\?)
print "HELP! Unknown option ${OPTARG}"
;;
esac
done
cab:~/work/standard> go.zsh -c -b foo -a zot
Number of args: 5
Here's x: c
I'm a c
I'm number 3
Here's my arg: -b
What happend to -a? The should be no argument to -c. Apparently -b
becomes the argument to -c, and foo terminates the argument list. This is
not correct behavior. Move the letters around in optstring and watch the
behavior change!
I'm running Solaris 2.5 on an UltraSPARC 1. I've tried this on Red Hat
Linux 4.1, too, and the bug appears there, also (same version of zsh).
Bash behaves correctly, like ksh.
Thanx in advance for your help!
____________________________
Christopher T. White
Advanced Data Engineering, Inc.
1310 Redwood Way, Ste. 120
Petaluma CA 94954
Voice: 707-794-7000
FAX: 707-794-7009
http://www.adei.com/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author