0

I was messing around with a log4j properties file and accidently made a folder with the following text ${foo} however I also have an environment variable named foo that points to a folder so thus if I do rm -rf "${foo}" it removes the folder $foo is pointing to, instead of the folder ${foo}. How can I specify to delete the folder in my current directory using a relative path instead of deleting the folder the environment variable points to?

Here is the layout to better help understand

$foo = /home/user/bar

${foo} = /home/user/${foo}

5
  • What is content of $foo?
    – cuonglm
    Commented Dec 16, 2014 at 17:03
  • @cuonglm the content of $foo is a folder called bar so if you entered $foo and did tab complete it would come up as /home/user/bar
    – jgr208
    Commented Dec 16, 2014 at 17:04
  • Use single quotes.
    – muru
    Commented Dec 16, 2014 at 17:16
  • @muru so like this '${foo}'?
    – jgr208
    Commented Dec 16, 2014 at 17:17
  • @jgr208 if the folder is named ${foo}, yep.
    – muru
    Commented Dec 16, 2014 at 17:20

1 Answer 1

2

String interpolation causes this. There are a number of ways to selectively prevent this from happening. The bash hackers wiki has some good examples, though the specifics may vary if you're not actually using bash.

In short, you can prevent interpolation with single quotes, or you can escape the characters.

[me:~/work]$ export foo=bar
[me:~/work]$ echo $foo
bar
[me:~/work]$ echo "\${foo} is set to ${foo}"
${foo} is set to bar

You must log in to answer this question.

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