Echo newline in Bash prints literal n

Echo newline in Bash prints literal n

You could use printf instead:

printf hellonworldn

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

Make sure you are in Bash.

$ echo $0
bash

All these four ways work for me:

echo -e Hellonworld
echo -e Hellonworld
echo Hello$nworld
echo Hello ; echo world

Echo newline in Bash prints literal n

echo $hellonworld

prints

hello
world

$ 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.

Leave a Reply

Your email address will not be published.