Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Jun 1998 08:12:29 -0400 (EDT)
From:      Jamie Bowden <jamie@itribe.net>
To:        Donn Miller <dmm125@bellatlantic.net>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: getopt and files that start with - or --
Message-ID:  <Pine.SGI.3.96.980617080837.11279F-100000@animaniacs.itribe.net>
In-Reply-To: <Pine.NEB.3.96.980616184616.202A-100000@myname.my.domain>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SGI.3.96.980617080837.11279F-100000>