Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to create a string and pass it to rm, but I'm having some difficulty making it work. I would like to remove everything in MY_PATH. Below is what I've attempted.

MY_PATH=/my/directory/
echo ${MY_PATH}'*' # This works as expected.
rm -vfr ${MY_PATH}'*' # This doesn't.

EDIT: I figured it out. I had a typo.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Your echo does not work properly. The shell is responsible for expanding wildcards, not rm.

rm -vfr "${MY_PATH}"*
share|improve this answer
    
or, better, use rm -vfr "${MY_PATH}"/*, in case the trailing / is forgotten when MY_PATH is set. As currently written, the difference between MY_PATH=/my/dir/ and MY_PATH=/my/dir is that the latter will not only delete /my/dir (the directory, not just the contents), but will also delete /my/dir1, /my/directory123, /my/directors_important_files ... And, best of all, check to verify that MY_PATH is actually set -- otherwise (with my suggested change) you'd try to (but probably fail, unless you're root) to delete everything under /* –  michael_n Apr 13 '13 at 23:32

You don't need the quotes, just use:
rm -vrf ${MY_PATH}*

share|improve this answer
2  
Unless $MY_PATH contains whitespace. –  Ignacio Vazquez-Abrams Jun 21 '11 at 15:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.