Stupid question...

Jim Rogers jimr at hp-lsd.COS.HP.COM
Wed May 29 08:46:23 AEST 1991


The reason you are having trouble with files beginning with "-" is that
this character is used by the rm command to signify an option.  It is
specifically excluded as a valid first character for a file name, as far as
the "rm" command is concerned.

What you need is an rm-like command which has no options.

The following short peice of C code will do the trick.  I called it dumbrm
because it is not smart enough to have any options.


/*************************************************************************
* This program will remove a file with any character in the file name
* because it has no options.
**************************************************************************/
#include <stdio.h>

main(argc, argv)
int argc;
char *argv[];
{
	int count;
	char answer[20];
	
	for(count = argc - 1; count > 0; count--)
	{
		fprintf(stderr,"Remove %s ? ", argv[count]);
		gets(answer);
		if (answer[0] == 'y' || answer[0] == 'Y')
		{
			if (unlink(argv[count]) != 0)
			{
				perror(argv[0]);
			}
		}
	}
}




Jim Rogers
Hewlett-Packard Company

Any opinion expressed or implied by this message are the sole responsibility
of the individual(s) above named and have no connection with any opinion,
real or imagined, expressed by my employer or any living individual.



More information about the Comp.unix.shell mailing list