Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 May 2000 22:30:08 +0100
From:      Mark Ovens <mark@ukug.uk.freebsd.org>
To:        cjclark@home.com
Cc:        Erik Trulsson <ertr1013@student.csd.uu.se>, questions@freebsd.org
Subject:   Re: getopt(1) or getopts(1)?
Message-ID:  <20000516223008.D1491@parish>
In-Reply-To: <20000515220432.A55458@cc942873-a.ewndsr1.nj.home.com>; from cjc@cc942873-a.ewndsr1.nj.home.com on Mon, May 15, 2000 at 10:04:33PM -0400
References:  <20000511231319.C1522@parish> <20000512084656.A1146@student.csd.uu.se> <20000512183403.A233@parish> <20000513013931.C39310@cc942873-a.ewndsr1.nj.home.com> <20000514110900.B232@parish> <20000514113604.A50543@cc942873-a.ewndsr1.nj.home.com> <20000515234055.C233@parish> <20000515220432.A55458@cc942873-a.ewndsr1.nj.home.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, May 15, 2000 at 10:04:33PM -0400, Crist J. Clark wrote:
> On Mon, May 15, 2000 at 11:40:56PM +0100, Mark Ovens wrote:
> > On Sun, May 14, 2000 at 11:36:04AM -0400, Crist J. Clark wrote:
> > > On Sun, May 14, 2000 at 11:09:00AM +0100, Mark Ovens wrote:
> > > >
> > 
> > [snip]
> >  
> > > > 
> > > > I'd almost got there, except I didn't know that shift wasn't needed.
> > > > 
> > > > > Almost makes life too easy, huh?
> > > > 
> > > > Almost. It does seem somewhat lacking in the error handling dept.
> > > > though. Using the example code above, if you do:
> > > > 
> > > > 	# foobar -o -a -b
> > > > 
> > > > then getopts(1) thinks that ``-a'' is the argument to ``-o''.
> > > 
> > > How do you know it is not?
> > > 
> > 
> > If ``-a'' is a valid argument to ``-o'' then it would require special
> > handling, not unlike filenames starting with ``-'', or containing
> > metacharacters, they need quoting.
> 
> Is this standardized somewhere? And since when do filenames starting
> with '-' need special handling all of the time? A lot of common tools
> do not behave that way,
> 
>   $ echo -v | grep -e -v
>   -v
>   $ { echo \#!/bin/sh; echo echo YES; } > -a
>   $ chmod 755 -a
>   $ sh -c -a
>   YES
>   $
> 
> Including sh(1) itself. But of course...
> 
>   $ rm -a
>   rm: illegal option -- a
>   usage: rm [-f | -i] [-dPRrvW] file ...
>          unlink file
>   $ rm -- -a
>   $
> 
> Lotsa times '-' files do.

OK, point taken :) I was just surprised that the newer getopts(1)
wasn't more comprehensive, but if that's the way it works then I'm
quite happy with it.

Thanks again for your help.

> -- 
> Crist J. Clark                           cjclark@home.com

-- 
        ...and on the eighth day God created UNIX
________________________________________________________________
      FreeBSD - The Power To Serve http://www.freebsd.org
      My Webpage http://ukug.uk.freebsd.org/~mark/
mailto:mark@ukug.uk.freebsd.org             http://www.radan.com



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000516223008.D1491>