Search code examples
bashescapingdollar-sign

How to echo a variable containing an unescaped dollar sign in bash


If I have a variable containing an unescaped dollar sign, is there any way I can echo the entire contents of the variable?

For example something calls a script:

./script.sh "test1$test2"

and then if I want to use the parameter it gets "truncated" like so:

echo ${1}
test1

Of course single-quoting the varaible name doesn't help. I can't figure out how to quote it so that I can at least escape the dollar sign myself once the script recieves the parameter.


Solution

  • The variable is replaced before the script is run.

    ./script.sh 'test1$test2'