• 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!

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • NewsVine
  • RSS
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

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...
    • Not looking forward to weeks where I can see most of the time will be in meetings and it's only Monday 3 weeks ago
    • finally broke the strings on my game racquet http://yfrog.com/0p8fxnj 3 weeks ago
    • bart stopped again due to "unauthorized person on the trackway"... I am really not having much luck with bart every time I come to downtown 3 weeks 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