zsh-users
 help / color / mirror / code / Atom feed
* bug in getopts
@ 1997-05-23 19:45 Christopher T. White
  0 siblings, 0 replies; only message in thread
From: Christopher T. White @ 1997-05-23 19:45 UTC (permalink / raw)
  To: zsh-users

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/


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-05-23 21:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-23 19:45 bug in getopts Christopher T. White

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).