Mail Archives: cygwin/2002/05/29/18:34:38
On Wed, 29 May 2002 17:45:35 -0400 Bernard A Badger <bab AT vx DOT com> wrote:
> > -----Original Message-----
> > From: Michael A Chase [mailto:mchase AT ix DOT netcom DOT com]
> > To: Bernard A Badger; cygwin AT cygwin DOT com
> > Subject: Re: trivial mkpasswd defect
> > On Wed, 29 May 2002 12:27:15 -0400 Bernard A Badger <bab AT vx DOT com> wrote:
> >
> > > > -----Original Message-----
> > > > On Wed, May 29, 2002 at 10:14:14AM -0400, Jon LaBadie wrote:
> > > > > mkpasswd reports '?' is a valid help option but fails to accept
> it.
> > > > > $ mkpasswd -?
> > > > > mkpasswd: unknown option -- ?
> > > >
> > > > Thanks. This will go away in the next version.
> > >
> > > I hope you mean that '-?' will work, not that '-?' will be taken out of the
> > > usage.
> >
> > In Unix envronments -h is more commonly used for help. '-?' as an option
> > is subject to filename expansion which can lead to odd behavior if it isn't
> > quoted.
> Well, the example from man 2 getopt has this:
>
> while ((c = getopt(argc, argv, ":abf:o:")) != -1) {
> switch(c) {
> ....
> case '?':
> fprintf(stderr,
> "Unrecognized option: -%c\n", optopt);
> errflg++;
> }
> }
> if (errflg) {
> fprintf(stderr, "usage: . . . ");
> exit(2);
>
> Which exemplifies the custom of printing the "usage" upon an error.
> Since '?' cannot be used as a getopt option, it is guaranteed to cause
> getopt to return '?' no matter what the option characters are.
>
> I saw this on a SGI Irix, and I checked at www.opengroup.org for the POSIX
> standard.
>
> Of course, if you're not following POSIX, and aren't using getopt, it may not
> work. Your personal experience of '-h' being a "help" option, probably carries
> less weight than the endorsement of POSIX ;-)
I don't see anything there that says that POSIX endorses '-?' for
displaying the usage message. It just shows how to handle invalid option
characters. If getopt sees an invalid character after '-' it returns '?' and puts the
invalid character ("?" in your example) in optopt. In that example, I'd expect to see
Unrecognized option -?
<<usage message>>
From 'man bash':
getopts optstring name [args]
getopts is used by shell procedures to parse positional parameters. optstring contains the
option characters to be recognized; if a character is followed by a colon, the option is
expected to have an argument, which should be separated from it by white space. The colon and
question mark characters may not be used as option characters. . . .
I don't have the man page for getopt() handy, but I think it contains the
same restriction.
--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -