> The real problem is that I want to replace some bash variables in a
> file and then print the output.
This is hard to do safely. The simplest approaches (eval, sed) will lead
to arbitrary code execution, or to an escaping mess.
> Please let me know if there is a convenient solution in bash.
I wrote: https://raw.githubusercontent.com/dualbus/myscripts/master/bin/stencil
Some time ago, precisely to deal with this issue. It's safe to use, because it
doesn't do any evaluation. It just replaces stuff that looks like bash
parameter expansions.
address@hidden ~ % x="'" y=IJK z=XYZ ./stencil <<< '"$x" $y $z'
"'" IJK XYZ
It's POSIX awk, so that should work for all awks.