I have a string: string="foo=bar boo=far rab=oof raf=oob"
I want to replace all white-space within the string with a newline character: string=${string// /$"\n"}
When I use printf
, bash prints:
~$ printf "%s" "$string"
foo=bar\nboo=far\nrab=oof\nraf=oob
However, when I mistyped the command as printf %s""$string
, I got:
~$ printf %s""$string
foo=bar
boo=far
rab=oof
raf=oob
What is the difference in printf "%s" "$string"
and printf %s""$string
that printf
will only interpret newline characters in one of the commands?