LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   line break on bash script (https://www.linuxquestions.org/questions/linux-general-1/line-break-on-bash-script-617324/)

ZAMO 01-29-2008 11:41 PM

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.

druuna 01-30-2008 12:29 AM

Hi,

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


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

Hope this helps.

ZAMO 01-30-2008 01:39 AM

Thank you , druuna.

1234ru 04-11-2010 11:59 AM

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>


cola 04-24-2010 12:09 PM

Quote:

Originally Posted by ZAMO (Post 3039656)
Thank you , druuna.

You can mark the thread as "[SOLVED]".

pixellany 04-24-2010 12:27 PM

Head's up folks!!!---Thread over 2 years old.


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