LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-29-2008, 11:41 PM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Rep: Reputation: 30
line break on bash script


Hi everyone,

I want to make line break indise a quoted text with echo.

echo "my name is zamo"

I want the output to be

my
name
is
zamo.


Thanks in advance.
 
Old 01-30-2008, 12:29 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Did you try something like this:
echo "my
name
is
zamo."


or:
echo -e "my\nname\nis\nzamo."

Hope this helps.
 
Old 01-30-2008, 01:39 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Original Poster
Rep: Reputation: 30
Thank you , druuna.
 
Old 04-11-2010, 11:59 AM   #4
1234ru
LQ Newbie
 
Registered: Apr 2010
Posts: 1

Rep: Reputation: 0
There is a pitfall (at least for beginners like me) related to linebreaks when working with variables.

Consider a text variable containing a line break in it:
Code:
var="first line
second line"
If you will echo your var somewhere (to output or into file), line breaks will be separated with spaces unless you put your variable into double quotes:

Code:
shell> var="first line
> second line"
shell> echo $var
first line second line
shell> echo "$var"
first line
second line
shell>
 
0 members found this post helpful.
Old 04-24-2010, 12:09 PM   #5
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,019

Rep: Reputation: 63
Quote:
Originally Posted by ZAMO View Post
Thank you , druuna.
You can mark the thread as "[SOLVED]".
 
0 members found this post helpful.
Old 04-24-2010, 12:27 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Head's up folks!!!---Thread over 2 years old.
 
1 members found this post helpful.
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 51 07-04-2013 08:16 PM
bash script 'for each command line argument' true_atlantis Linux - Newbie 3 01-28-2009 01:51 PM
looking for string on particular line - bash script tara Linux - General 9 12-14-2005 05:43 PM
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 12:08 AM
Bash script text line into an array toolshed Programming 1 06-13-2005 05:49 PM


All times are GMT -5. The time now is 09:32 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