Date: Tue, 16 Jun 1998 19:10:06 +0000 (GMT) From: Donn Miller <dmm125@bellatlantic.net> To: hackers@FreeBSD.ORG Subject: getopt and files that start with - or -- Message-ID: <Pine.NEB.3.96.980616184616.202A-100000@myname.my.domain>
next in thread | raw e-mail | index | archive | help
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:
/* unlink: force removal of ALL files
usage: unlink file1 file2 .. filen
just like rm -f except no options */
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int i;
if (argc == 1) {
fprintf(stderr, "usage: unlink file[s].\n");
exit(-1);
}
for (i = 1 ; i < argc ; i++) {
if (unlink(argv[i]) == 0)
printf ("removed %s\n", argv[i]);
else
perror(argv[i]);
}
return 0;
}
Or else maybe libc.so.* could use a hack to deal with these stange
situations.
Another less attractive solution would be to just use the code above,
install it in /usr/local/bin, and use it like rm -f.
Donn
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.NEB.3.96.980616184616.202A-100000>
