This
STR=\"Hello\\nWorld\"
echo $STR
produces as output
Hello\\nWorld
instead of
Hello
Wo
The problem isn't with the shell. The problem is actually with the echo
command itself, and the lack of double quotes around the variable interpolation. You can try using echo -e
but that isn't supported on all platforms, and one of the reasons printf
is now recommended for portability.
You can also try and insert the newline directly into your shell script (if a script is what you're writing) so it looks like...
#!/bin/sh
echo "Hello
World"
#EOF
or equivalently
#!/bin/sh
string="Hello
World"
echo "$string" # note double quotes!