zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: (Fwd) Re: getopts question
Date: Tue, 15 Apr 2003 15:01:57 -0700	[thread overview]
Message-ID: <030415150157.ZM28500@candle.brasslantern.com> (raw)

The latest zsh 4.1.x from CVS, and 4.0.x, both print "1" for the test script
quoted below.  Apparently they should print "2".  Commentary?

--- Forwarded mail from David Korn <dgk@research.att.com>

Date: Tue, 15 Apr 2003 16:03:11 -0400 (EDT)
From: David Korn <dgk@research.att.com>
To: shell@research.att.com
Subject: Re: getopts question

Subject: Re: getopts question
--------

> What is the following script supposed to print if invoked as `foo -a'?
> 
> --- snip ---
> #!/bin/sh
> 
> while getopts : f
> do
>     case "$f" in
>     \?)  break;;
>     esac
> done
> 
> echo $OPTIND
> --- snip ---
> 
> On every version of bash but the most recent it printed 1.
> 
> On ash and pdksh it prints 1.
> 
> Chet tells me that 2 is the right thing to print, since recent
> versions of att-ksh print 2 and the posix manual says so.
> 
> This breaks historical practice and is a pain to detect. What's
> the rationale behind the change? I would assume since getopts
> actually did not parse something successfully, it should not
> increment $OPTIND?
> 
> christos
> 

This came up in 1995 when shell conformance tests were being
run on ksh, and I was forced to change the behavior then.

I tried to argue that the behavior was not specified, but  they
disputed my claim.  I have included some e-mail below.
It looks like we are stuck with 2 being the correct behavior.

>> getopts:
>>
>> A while back I had mentioned that some VSC getopts tests failed because
>> OPTIND wasn't incremented after reading a non-option.  The test writers
>> disputed my argument (based on your mail) that the behavior wasn't well
>> specified for error conditions.  They cited POSIX 4.27.2, lines 4631-4633
>> among the evidence that the behavior is specified.  After several exchanges
>> I was convinced by their arguments and made the following change to
>> optget() in libast/misc/optget.c:

Lines 4631-4633 state.
"Each time it is invoked, the getopts utility shall place the value of
the next option in the shell variable specified by the name operand and
the index of the next argument to be processed in the shell variable
OPTIND."

David Korn
research!dgk
dgk@research.att.com
____________________________________________________________
To unsubscribe from this list, please send the following
two-line message to majordomo@research.att.com, in which
your_email_address should be replaced by the address you
used when you subscribed to the list:
unsubscribe shell your_email_address
end


---End of forwarded mail from David Korn <dgk@research.att.com>


             reply	other threads:[~2003-04-15 22:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-15 22:01 Bart Schaefer [this message]
2003-04-25 10:23 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=030415150157.ZM28500@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).