From owner-freebsd-hackers Tue Jun 16 16:11:51 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA15307 for freebsd-hackers-outgoing; Tue, 16 Jun 1998 16:11:51 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from iconmail.bellatlantic.net (iconmail.bellatlantic.net [199.173.162.30]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA15297 for ; Tue, 16 Jun 1998 16:11:42 -0700 (PDT) (envelope-from dmm125@bellatlantic.net) Received: from myname.my.domain (client201-122-12.bellatlantic.net [151.201.122.12]) by iconmail.bellatlantic.net (IConNet Sendmail) with SMTP id TAA23004 for ; Tue, 16 Jun 1998 19:10:12 -0400 (EDT) Newsgroups: comp.unix.bsd.freebsd.misc,comp.os.linux.misc Date: Tue, 16 Jun 1998 19:10:06 +0000 (GMT) From: Donn Miller X-Sender: dmm125@myname.my.domain To: hackers@FreeBSD.ORG Subject: getopt and files that start with - or -- 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 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 #include 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