bashechonewline

Echo newline in Bash prints literal \n


How do I print a newline? This merely prints \n:

echo -e "Hello,\nWorld!"

Output:

Hello,\nWorld!

Solution

  • Use printf instead:

    printf 'Hello, \nWorld!\n'
    

    printf behaves more consistently across different environments than echo.