Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14259

Re: $OPTIND varibale value is different from sh

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: $OPTIND varibale value is different from sh
Date 2018-06-20 16:03 -0400
Message-ID <mailman.2315.1529525010.1292.bug-bash@gnu.org> (permalink)
References <ea25c4c012ab73dff24d28714d4bd8@cweb13.nm.nhnsystem.com> <20180620123950.i6etdbcjgodbfse6@eeg.ccf.org> <2be3b04b-7409-d5ed-7e27-bd7f414fc267@inlv.org>

Show all headers | View raw


On 6/20/18 2:09 PM, Martijn Dekker wrote:
> Op 20-06-18 om 13:39 schreef Greg Wooledge:
>> I really don't understand what you're doing here, either.  The only
>> use of OPTIND is after the final call to getopts, when there are no
>> more options to process.  At that point, OPTIND tells you how many
>> times you have to "shift" to get rid of all the options that were
>> processed.  (And you have to subtract 1, because legacy historical
>> reasons.)
> 
> In other words, because all the options have now been processed, OPTIND
> points to the first argument *after* the list of options. I don't see how
> that is "because legacy historical reasons". It seems both logical and
> useful to me.

It enables the universal idiom `shift $(( $OPTIND - 1 ))' to throw away
the options and option arguments and deal with the rest of the arguments.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: $OPTIND varibale value is different from sh Chet Ramey <chet.ramey@case.edu> - 2018-06-20 16:03 -0400

csiph-web