LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sh scripting -- escape * character? (https://www.linuxquestions.org/questions/linux-newbie-8/sh-scripting-escape-%2A-character-591162/)

Brender 10-11-2007 04:33 PM

sh scripting -- escape * character?
 
rm -rf * is a dangerous command.

Believe me.

I use it several times a day in the course of development. Once or twice it's bitten me pretty badly... usually with accidentally executed commands from the history while I'm trying to work past the abilities of my current caffeine intake.

Onto the problem.

rm -ri * is no good, because I don't want to push 'y' all day.

I was thinking of aliasing rm to a shell script that parses the arguments. If it sees '-rf *' as an arg, it simply asks 'Are you sure?', and waits for a yes or no answer.

I can't seem to escape the * character. I've tried \*, \042. Various mixes of quotes. I'm actually thinking this is futile now, for if I print the arguments the script is fed, it's a list of all the files in the directory.

Another option is do the confirmation whenever it see -rf. This might annoy me though, as I frequently delete directories this way and haven't shot myself in the foot with it.

Yet.

Is there some other way to make a slightly less interactive rm -r *?

weibullguy 10-11-2007 04:45 PM

Code:

rm -rfI
only asks you once if you want to delete all arguments recursively. If you say yes, it deletes everything with no more prompting. If you say no, it deletes nothing.

Brender 10-12-2007 09:33 AM

Hmm... man page didn't give me that option. Tried it on my RHEL4 work box, and it says invalid option. Seems to work on my FreeBSD box though. I guess it's time to find a newer version...

Thanks!


All times are GMT -5. The time now is 02:47 AM.