rm $(filename)*

hi ,

rm -f $(filename)*

removes ,not only $filename* but all the files in the directory .Why??
Imagine I have scripted for some one and a half hour and all the files are removed. F :smiley: rustrated ..really .

regards,
sakthi

rm -f ${filename}* 

Hi sakthi,

Straight forward one really. By using the ( ) brackets you imply that $filename is a command, when infact it is a variable. rm will complain that it's an invalid command and ignores it, thus executing rm -f *

As vgersh99 showed the correct format is to use the curly braces { }

Perhaps this advice comes a little too late but when ever I write scripts that contain any form of the rm command I always take a snapshot of my virtual machines. I know this might not be achievable for everyone but it's always worth doing this in a test environment first. Alternatively you could always use the -i argument in a test run of your script first as this will prompt before removing any files.

If it makes you feel any better I've pulled a few classic manouvers in my time including the following line in my code before:

rm -dfrv /* >> /$LOG

and yes I was logged in as root. What I meant to have in there was rm -dfrv * :smiley:

Nice Reply!!! _spare_ribs [ i m learning from errors ]
Thanks really....

that's the priceless value of forums : you can always learn from technical discussions, and see some nice examples and advices like the one from "_Spare_Ribs_"