Problems with linebreak in terminal (\n doesn't create linebreak)

Hello! I've recently started to migrate my embedded software development from my laptop to my gorgeous new iMac, but I've come across a rather annoying problem.

Linebreaks doesn't work properly in the terminal. If I type
echo "Hello \n Linebreak" it just types Hello \n Linebreak and doesn't interpret the newline-character correctly.

My version of Mac OS X and keyboard are both Swedish (Pro-Swe). Any hints or tips that could help me take the final step and finally switch my dell laptop to a macbook? 🙂

Thanks in advance / Martin

iMac 24" 2.4GHz C2D, Mac OS X (10.4.10), Localization: Swedish.

Posted on Aug 24, 2007 4:38 AM

Reply
3 replies

Aug 24, 2007 7:50 AM in response to Martin Nordén

Hi Martin,

I discovered that it also works in zsh.


Welcome to zsh! 😉
If you are using zsh, then you don't need -e unless you explicitly set the BSD_ECHO option.

If you are using bash instead, but don't want to add an option -e, then put the following into your .bashrc or .bash_profile, whicherver appropriate:

shopt -s xpg_echo


Another method is to use

echo $'foo bar'

This works both in bash and zsh.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Problems with linebreak in terminal (\n doesn't create linebreak)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.