Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .