From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12919 invoked from network); 23 Nov 1999 21:40:57 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 23 Nov 1999 21:40:57 -0000 Received: (qmail 1621 invoked by alias); 23 Nov 1999 21:40:50 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8762 Received: (qmail 1612 invoked from network); 23 Nov 1999 21:40:45 -0000 From: "Bart Schaefer" Message-Id: <991123214038.ZM29906@candle.brasslantern.com> Date: Tue, 23 Nov 1999 21:40:38 +0000 In-Reply-To: <19991123182219.A7795@thelonious.new.ox.ac.uk> Comments: In reply to Adam Spiers "Re: "getopts" bugs and bad interactions with "shift"" (Nov 23, 6:22pm) References: <991123180832.ZM29676@candle.brasslantern.com> <19991123182219.A7795@thelonious.new.ox.ac.uk> X-Mailer: Z-Mail Lite (5.0.0 30July97) To: zsh-workers@sunsite.auc.dk Subject: Re: "getopts" bugs and bad interactions with "shift" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Nov 23, 6:22pm, Adam Spiers wrote: > Subject: Re: "getopts" bugs and bad interactions with "shift" > Bart Schaefer (schaefer@candle.brasslantern.com) wrote: > > Question: Is "getopts" based on some standard or emulated behavior of > > some other shell, or is it strictly a zsh thing? > > getopt is part of GNU libc [...] In case it wasn't obvious from Zefram's post, "getopts" != "getopt". The GNU "getopt" command (short-args-only form) is very roughly equivalent to function getopt () { optstr=":$1"; shift got=() ret=0 while getopts "$optstr" opt do if [[ $opt == [?] ]] then echo getopt: invalid option -- "$OPTARG" 1>&2 ret=1 else got=("$got[@]" "-$opt" ${OPTARG:+"$OPTARG"}) fi done shift $OPTIND # $((OPTIND-1)) if 3.0.7 or before echo "" "$got[@]" -- "$@" return $ret }