From owner-freebsd-questions Thu May 11 23:47:18 2000 Delivered-To: freebsd-questions@freebsd.org Received: from merganser.its.uu.se (merganser.its.uu.se [130.238.6.236]) by hub.freebsd.org (Postfix) with ESMTP id 8C3EA37B721 for ; Thu, 11 May 2000 23:47:09 -0700 (PDT) (envelope-from ertr1013@student.csd.uu.se) Received: from regulus.student.UU.SE ([130.238.5.2]:34814 "HELO ertr1013.student.csd.uu.se") by merganser.its.uu.se with SMTP id ; Fri, 12 May 2000 08:46:59 +0200 Received: (qmail 1162 invoked by uid 1001); 12 May 2000 06:46:56 -0000 Date: Fri, 12 May 2000 08:46:56 +0200 From: Erik Trulsson To: Mark Ovens Cc: questions@FreeBSD.ORG Subject: Re: getopt(1) or getopts(1)? Message-ID: <20000512084656.A1146@student.csd.uu.se> References: <20000511231319.C1522@parish> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20000511231319.C1522@parish>; from mark@dogma.freebsd-uk.eu.org on Thu, May 11, 2000 at 11:13:19PM +0100 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, May 11, 2000 at 11:13:19PM +0100, Mark Ovens wrote: > Can someone clarify getopt(1) and getopts(1)? According to sh(1): > > getopts optstring var > The POSIX getopts command. The getopts command deprecates the > older getopt(1) command..... > > but there is no manpage for getopts(1), only getopt(1). The latter > includes some sample code which works fine, however if I change > ``getopt'' to ``getopts'' in this code I get: > > parish:/usr/marko{89}% ./foobar -b > getopts: -b: bad variable name > Usage: ... > parish:/usr/marko{90}% > > Since getopt(1) is deprecated it would be better to use getopts(1). > Can anyone explain the above error, or point me to some documentation > for getopts(1)? > On my system (4.0-stable) there is a manpage for getopts(1). It just a link to buiiltin(1) which says that it is a builtin command in sh(1). The manpage for sh(1) has the following to say about getopts: getopts optstring var The POSIX getopts command. The getopts command deprecates the older getopt(1) command. The first argument should be a series of letters, each possibly followed by a colon which indicates that the option takes an argument. The specified variable is set to the parsed option. The index of the next argument is placed into the shell variable OPTIND. If an option takes an argument, it is placed into the shell variable OPTARG. If an invalid option is encountered, var is set to `?''. It returns a false value (1) when it encounters the end of the options. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message