LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2007, 04:33 PM   #1
Brender
LQ Newbie
 
Registered: Sep 2003
Distribution: Mandrake 9.1
Posts: 5

Rep: Reputation: 0
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 *?
 
Old 10-11-2007, 04:45 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
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.
 
Old 10-12-2007, 09:33 AM   #3
Brender
LQ Newbie
 
Registered: Sep 2003
Distribution: Mandrake 9.1
Posts: 5

Original Poster
Rep: Reputation: 0
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
echo escape character weirdness insecurityman Programming 7 10-20-2008 04:20 AM
awk escape character for colon in string quadmore Programming 2 02-27-2007 04:56 PM
.bashrc is there an escape character for alias? acummings Slackware 11 01-13-2007 10:56 AM
Escape character ? juanb Linux - Newbie 2 08-31-2004 10:03 AM
Escape character not working in shell script philipz Programming 1 04-29-2004 09:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration