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.
$a
is simply random text but it needs to be saved with escaped spaces? Should I run grep and replace spaces with\
? – Philip Kirkbride Nov 21 '17 at 16:03echo $a | tr ' ' '\ ' > /tmp/a
? – Philip Kirkbride Nov 21 '17 at 16:12