Echo newline in Bash prints literal \n Echo newline in Bash prints literal \n bash bash

Echo newline in Bash prints literal \n


You could use printf instead:

printf "hello\nworld\n"

printf has more consistent behavior than echo. The behavior of echo varies greatly between different versions.


Make sure you are in Bash. All these four ways work for me:

echo -e "Hello\nworld"echo -e 'Hello\nworld'echo Hello$'\n'worldecho Hello ; echo world


echo $'hello\nworld'

prints

helloworld

$'' strings use ANSI C Quoting:

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.