Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-12-2008
Registered User
 
Join Date: Jun 2007
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
new line in echo

Hi
i would like disply the new line in echo command.

i have input like:
echo " X1 02:12:13 X2 03:02:12 "

out put:

X1 02:12:13
X2 03:02:12

can you tell how can use new line option in echo command.
Sponsored Links
    #2  
Old 03-12-2008
Registered User
 
Join Date: Aug 2007
Location: Bangalore
Posts: 390
Thanks: 0
Thanked 0 Times in 0 Posts
You can enter a new line like this.


Code:
echo "\n"

Sponsored Links
    #3  
Old 03-12-2008
Moderator
 
Join Date: Feb 2007
Location: The Netherlands
Posts: 7,505
Thanks: 73
Thanked 474 Times in 453 Posts

Code:
echo "X1 02:12:13\nX2 03:02:12"

Regards
    #4  
Old 03-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 8 Times in 8 Posts
Actually, not all versions of echo permit backslash escape codes, but all versions of the shell should allow newlines inside quoted strings.


Code:
echo "X1 02:12:13
X2 03:02:12"

Yup, that's a newline smack dab in the middle of the quoted string.
Sponsored Links
    #5  
Old 12-27-2008
Registered User
 
Join Date: Dec 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Pass the -e parameter to enable interpretation of backslash escapes(which us off by default). Like this:
PHP Code:
echo -"hello\nworld!" 
Jostein Topland
Sponsored Links
    #6  
Old 12-27-2008
cfajohnson's Avatar
Shell programmer, author
 
Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,866
Thanks: 0
Thanked 100 Times in 93 Posts
Quote:
Originally Posted by jtopland View Post
Pass the -e parameter to enable interpretation of backslash escapes(which us off by default). Like this:
PHP Code:
echo -"hello\nworld!" 

The -e option is not standard. A POSIX-compliant echo does not accept any options:


Code:
$ echo -e "12 34\n56 78"
-e 12 34\n56 78

The simplest and most portable way is to use printf:


Code:
string="12 34\n56 78"
printf "%b\n" "$string"

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
echo two command output in the same line chuikingman Shell Programming and Scripting 4 01-25-2011 01:38 AM
Echo and a command's output on the same line codyhazelwood Shell Programming and Scripting 7 03-23-2010 07:24 PM
echo and new line melanie_pfefer UNIX for Advanced & Expert Users 6 12-11-2008 01:55 PM
echo just 1 line before execution/set +-x fabulous2 Shell Programming and Scripting 3 12-19-2007 01:52 AM
how to echo the file contents LINE BY LINE newbie168 Shell Programming and Scripting 4 02-22-2006 05:43 AM



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