From owner-freebsd-questions Tue May 16 20:24:46 2000 Delivered-To: freebsd-questions@freebsd.org Received: from rhenium.btinternet.com (rhenium.btinternet.com [194.73.73.93]) by hub.freebsd.org (Postfix) with ESMTP id 7B0D537B68A for ; Tue, 16 May 2000 20:24:43 -0700 (PDT) (envelope-from mark@ukug.uk.freebsd.org) Received: from [62.7.68.105] (helo=parish.my.domain) by neodymium with esmtp (Exim 2.05 #1) id 12rouw-0005sP-00; Tue, 16 May 2000 22:30:19 +0100 Received: (from mark@localhost) by parish.my.domain (8.9.3/8.9.3) id WAA02083; Tue, 16 May 2000 22:30:09 +0100 (BST) (envelope-from mark) Date: Tue, 16 May 2000 22:30:08 +0100 From: Mark Ovens To: cjclark@home.com Cc: Erik Trulsson , questions@freebsd.org Subject: Re: getopt(1) or getopts(1)? Message-ID: <20000516223008.D1491@parish> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i 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 Organization: Total lack of Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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