• Home
  • About
Blue Orange Green Pink Purple

Inserting new line in echo command

Posted in Mac OS, Tutorial. on Thursday, July 9th, 2009 by Kang Tags: featured, shell scripting
Jul 09

Out of curiosity and the perfectionist in me, I “had” to print a line of text in the output inside a BASH shell script. I didn’t really want to split them into multiple echo statements since it’s a waste of space and actually harder to read for me. The first thing I tried was:

> echo “Line1\nLine2″ # Line1\nLine2

That clearly didn’t work out so well… so I thought maybe my Mac (OS X 10.5.7) likes ‘\r\n’ more:

> echo “Line1\r\nLine2″ # line1\r\nline2

Still nope! As I found out later on though, not all versions of echo supports backslash escape characters. A quick look up in the MAN page for echo revealed that I needed to pass in the -e option in order to enable this capability:

> echo -e “Line1\nLine2″

Line1
Line2

TADA! Third time is the charm!

Be Sociable, Share!
  • Tweet

Leave a Reply

One Giant Robot After Another

  • Recent Ramblings
    • Improving VLC Player load times of .MKV files on Snow Leopard
    • Updating Your Ruby on Rails Application Custom Environment via Passenger Pane
    • Enhanced Open Terminal Here, for Leopard at Maururu
    • Inserting new line in echo command
    • One Giant Robot After Another
  • What I'm Doing...
    • Getting ready for commencement (1/2)! http://t.co/3EOdQ5AR 1 hr ago
    • getting to leave my name on school property ;) 10 hrs ago
    • Ugh!!! Hotel internet, why you no let me download jars? 1 day ago
    • More updates...
  • Calendar
    July 2009
    M T W T F S S
    « Jun   Aug »
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
  • Tags
    apple applications featured hosting iPhone Mac OS X Passenger performance productivity review Ruby on Rails shell scripting Snow Leopard technical tips Tutorial
  • Archives
    • November 2009
    • August 2009
    • July 2009
    • June 2009
  • Search






  • Home
  • About

© Copyright One Giant Robot After Another. All rights reserved.
Designed by FTL Wordpress Themes brought to you by Smashing Magazine

Back to Top