Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 am running this little test script I wrote :


testHarness <<runTest

from the command line :

./test.sh "1092$212"

but the dollar sign is being stripped out. If I escape it, it works. But I thought the double quotes would protect me from needing to do this. Can someone please help me understand whats going on and how to fix this?

share|improve this question
The problem is that it's ambiguous--even for me as a human--what you want here, so the computer has no chance. Perhaps the bash interpreter is trying to get $212. Bash silently fails if you try to expand a variable that doesn't exist, thus the $ gets stripped out. Consider wrapping your variables inside brackets, e.g. "1092${2}12" – Brian Peterson Oct 17 '13 at 9:35
up vote 12 down vote accepted

Variables are still expanded inside double quotes. If you want to avoid this behavior you should use single quotes instead.

share|improve this answer
Thank you. This works. Is there a reason for this? – Amir Afghani May 11 '11 at 19:17
Yes. It was designed that way! It's actually quite useful to be able to expand variables inside a quoted string. It's a feature. If you don't want the behavior, use single quotes, that's what they were designed for. – Caleb May 11 '11 at 19:20

Your Answer


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.