Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 May 2000 22:04:33 -0400
From:      "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com>
To:        Mark Ovens <mark@dogma.freebsd-uk.eu.org>
Cc:        Erik Trulsson <ertr1013@student.csd.uu.se>, questions@freebsd.org
Subject:   Re: getopt(1) or getopts(1)?
Message-ID:  <20000515220432.A55458@cc942873-a.ewndsr1.nj.home.com>
In-Reply-To: <20000515234055.C233@parish>; from mark@dogma.freebsd-uk.eu.org on Mon, May 15, 2000 at 11:40:56PM %2B0100
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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.
-- 
Crist J. Clark                           cjclark@home.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?20000515220432.A55458>