Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Fedora This forum is for the discussion of the Fedora Project.


  Search this Thread
Old 05-25-2009, 06:11 PM   #1
LQ Newbie
Registered: Apr 2008
Location: Hobart, Tasmania, Australia
Distribution: Centos, Ubuntu, Debian, Fedora/RH
Posts: 2

Rep: Reputation: 0
Command Line Expansion & echo

Hi all

I am having trouble with new line character substitution on the command line output : Fedora10

have tried the following:
echo text one `\n' text two
-- note grave accent followed by backslash, char n and lastly single quote

echo -e text one `\n' text two

echo text one $'\n' text two

I get either a) errors or be ) the secondary prompt > with not output

what I am trying to do is produce the following from the above command:
text one
text two

Old 05-25-2009, 06:24 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,839
Blog Entries: 14

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Put double quotes around the whole line to be echoed:
echo "text one \n text two"

Also I notice the character you have before the \n and after it are not the same so it wouldn't work. Quoting characters must match.
Old 05-25-2009, 06:26 PM   #3
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 267

Rep: Reputation: 58
 echo -e "text one \ntext two\n"
Old 05-25-2009, 08:18 PM   #4
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
also echo -e 'text one \ntext two'

note missing space after \n othewise output will be

text one
_text two

I used underscore where you would have space because LQ flattend the lines

I think the quotes in your original preserve \n as the two charater rather than a newline.

Last edited by archShade; 05-25-2009 at 08:22 PM.
Old 05-26-2009, 12:30 AM   #5
LQ Newbie
Registered: Apr 2008
Location: Hobart, Tasmania, Australia
Distribution: Centos, Ubuntu, Debian, Fedora/RH
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the suggestions

Finally got it to work with echo -e text one\\ntext two

A colleague suggested that something is weird with the terminal settings ... do you think this could the problem?

BTW Fedora session is being run inside VM Server

seems strange that Ubuntu, Centos, Fedora 5 had no problem with the suggestions & previous attempts
(had friends at uni check this out on other Linux versions)


echo, line, substitution

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does bash shell parameter expansion run the risk of overflowing command line buffer? david1941 Linux - Software 1 04-28-2009 10:13 PM
What is wrong in the statement: $line || echo "error" && break; nadavvin Linux - General 1 08-05-2006 05:25 AM
What is command line expansion? Wizzy Linux - Newbie 2 03-22-2006 01:50 PM
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 12:08 AM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 11:31 AM

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration