LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices

Reply
 
Search this Thread
Old 05-25-2009, 06:11 PM   #1
Merrida
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:
[Fedora10]$
text one
text two
[Fedora10]$


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

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 267

Rep: Reputation: 57
try:
Code:
 echo -e "text one \ntext two\n"
Dave
 
Old 05-25-2009, 08:18 PM   #4
archShade
Member
 
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
Merrida
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)
 
  


Reply

Tags
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 11:45 PM.

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