new line in shell script | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

new line in shell script

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-17-2008
shantanuo shantanuo is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 23 September 2013, 3:07 AM EDT
Location: Mumbai
Posts: 81
Thanks: 1
Thanked 0 Times in 0 Posts
new line in shell script

This may sound elementary question. But how do I add new line in my shell script?
This works:
echo '###'

This prints \n ### and not ### on a new line...
echo "\n ###"
Sponsored Links
    #2  
Old 09-17-2008
avronius avronius is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 22 May 2013, 8:38 AM EDT
Location: Calgary
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Have you tried

Code:
echo ""
echo "###"

Sponsored Links
    #3  
Old 09-17-2008
subhendu81 subhendu81 is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 10 October 2014, 8:11 AM EDT
Location: pune
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
hi,
just try

echo "\n"
    #4  
Old 09-17-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts
There are different versions of echo, some of which will print a newline when they see \n (and some will only do it when invoked with the -e option).

The portable way is to echo nothing, since echo (without options) will always supply a newline.


Code:
echo

More generally, you might be surprised to learn that strings are allowed to contain newlines. It looks funny, but it can be handy.


Code:
echo "foo
bar
baz"

For long sequences of text, you should also consider here documents.


Code:
cat <<HERE
foo
bar
baz
HERE

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
linux shell script to take variables from two different files line by line atanubanerji Shell Programming and Scripting 4 10-13-2011 05:04 AM
Shell script to read a text file line by line & process it... new_to_shell Shell Programming and Scripting 8 09-13-2011 05:45 AM
get the fifth line of a text file into a shell script and trim the line to extract a WORD venu Shell Programming and Scripting 3 12-08-2010 09:46 PM
how can u read a file line by line in shell script ? abhigrkist Shell Programming and Scripting 4 11-08-2010 06:38 PM
Shell script to count number of ~ from each line and compare with next line Ganesh Khandare Shell Programming and Scripting 3 09-29-2010 05:06 PM



All times are GMT -4. The time now is 07:43 AM.