From owner-freebsd-hackers Wed Jun 17 05:24:39 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id FAA10569 for freebsd-hackers-outgoing; Wed, 17 Jun 1998 05:24:39 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from animaniacs.itribe.net (gatekeeper.itribe.net [209.49.144.254]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id FAA10559 for ; Wed, 17 Jun 1998 05:24:37 -0700 (PDT) (envelope-from jamie@itribe.net) Received: from localhost (jamie@localhost) by animaniacs.itribe.net (950413.SGI.8.6.12/950213.SGI.AUTOCF) via SMTP id IAA12744; Wed, 17 Jun 1998 08:12:29 -0400 Date: Wed, 17 Jun 1998 08:12:29 -0400 (EDT) From: Jamie Bowden To: Donn Miller cc: hackers@FreeBSD.ORG Subject: Re: getopt and files that start with - or -- In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 16 Jun 1998, Donn Miller wrote: > Hi > > I had some problems with filenames that start with - or --. The getopt() > library function interprets arguments beginning with "-" passed to > programs like ls, rm, grep as options. This is bad if you try to do > rm -* or > ls -* or grep "a string" -*. I thought maybe a provision could be made to > "ignore the following arguments" passed to getopt(). > > Say you have a file named --weird.jpg. You want to remove this, so you > do: > > rm --* or just --weird.jpg. rm will complain about the invalid option > --weird.jpg, which isn't actually an option but a filename. "ls" will > also complain, as well as other programs using getopt(). So I thought > that maybe getopt could use an option such as ---i or ---ignore to ingore > all other options. Otherwise, you would have to use a program like this > to remove the offending files: Unneccessary code deleted. >From the rm manpage: NOTE The rm command uses getopt(3) to parse its arguments, which allows it to accept the `--' option which will cause it to stop processing flag op- tions at that point. This will allow the removal of file names that be- gin with a dash (`-'). For example: rm -- -filename The same behavior can be obtained by using an absolute or relative path reference. For example: rm /home/user/-filename rm ./-filename This is useful for commands that do not use getopt(3) to parse the com- mand line arguments. Jamie Bowden Systems Administrator, iTRiBE.net To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message