I am writing a script that deals with hex color values and I want to substitute in a user provided variable after a hash mark like so:
HEX=$1
COLOR='#$HEX'
But this fails as I believe it is interpreting the hash as a comment? How do I escape the hash so that I can have a variable which contains a string with a hash in it?
That fails because you’re using single quotes. There’s no variable substitution inside single quotes. Instead, use double quoted: