How to print ${STR1} and $STR2 – not their contents – into a file?

I need to print expressions ${STR1} and $STR2 into a file — not the content of the variables. How can I accomplish this using echo or printf?


You just need to escape the $ character, as in

echo "${STR1}" >> myfile


echo "$STR2" >> myfile

Alternatively, you can use single quotes

echo '${STR1}' '$STR2'

Leave a Reply

Your email address will not be published. Required fields are marked *