I want to echo a variable with spaces into a text file.
a=a\ b\ c
echo $a > /tmp/a
The above results in a file with a b c in it. What if I need the file to read a\ b\ c?
I've tried printf %q $a but that doesn't seem to do what I want either.
Note: Also assume that I don't produce the content of $a it is passed to me outside my control. I just need to make sure it is saved with escaped spaces.