Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detect string

Status
Not open for further replies.

pjsatif

IS-IT--Management
May 31, 2007
9
0
0
DE
Hello,

I need to build a script to detect some keywords in the command prompt and when of that keywords appears, just execute the command (query, etc...) after a confirmation.

example:

Command -> rm file.ext
Warning -> "sure to rm?"
User input -> yes

If user type yes the command is executed, if not nothing happens.

Any idea?

Many thanks.
 
You could alias rm -i (interactive) to rm so that you are asked to confirm every time rm is invoked.

I want to be good, is that not enough?
 
read ANS?"Are you sure to do this"

while [ $ANS = "yes" ]
do
...
done
 
For commands like rm, you can do that using KenCunningham's suggestion because the command itself provide such a feature but for others i'm not sure how you will be able to do so! What other commands you have in mind?

One way (which is not a very good one if the user know the renamed command name) is to rename the origional command and write a script of the command name that will call the actual renamed command but by warning the user before doing so as you described above. You can use imchinese' suggestion in there!

Regards,
Khalid
 
Hi, I've planned to develop a daemon that detects keywords like RM, DELETE, UPDATE, etc....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top