Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Bernard A Badger" To: "Michael A Chase" , Subject: RE: trivial mkpasswd defect Date: Thu, 30 May 2002 10:00:24 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 > On Wed, 29 May 2002 17:45:35 -0400 Bernard A Badger wrote: [SNIP] > 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 -? > <> > > >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. Oh, I didn't understand what you meant. You think that '-?' cannot be used as an option. Yes, it's true that you cannot have '?' as an legal option character. This is because getopt returns the option character that was used, and '?' is used as an error indication. Whenever the user calls the command with an error, '?' is returned instead of a legal option character. Thus, all illegal options -- and options with missing arguments --- conveniently come back as a single character '?'. But so does '-?' ! That means that '-?' is _always_ illegal. The programmer cannot make -? a legal option, but the user can deliberately invoke it as an illegal option syntax. The user can _rely_ on it being erroneous! If you provide an illegal option, the command is supposed to print a usage message to stderr and fail (return a non-zero error code). That's exactly what the example did. Since this is hard-coded into the getopt() function, many commands are written with '-?' in mind. Since the user can get a usage this way, it's not necessary, in POSIX, to have -h as an option. (But see my other mail about GNU and --help requirement.) -- 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/