Single quote within double quotes and the Bash reference manual
The '
single quote character in your echo
example gets it literal value (and loses its meaning) as it enclosed in double quotes ("
). The enclosing characters are the double quotes.
What you can do is print the single quotes separately:
echo "'"'$a'"'"
or escape the $
:
echo "'\$a'"
You misunderstand the documentation:
having it's special meaning inside, would shield $ from the special interpretation
"Having its special meaning" means that it is interpreted specially not literally. Single quotes prevent $
from being expanded. But single quotes within double quotes are literal characters i.e. they do not affect anything. If you want the output $a
then you need echo '$a'
.