You are not logged in.

#1 2009-08-28 19:00:05

V for Vivian
Member
Registered: 2009-04-28
Posts: 52

[solved] bash: multiple lines in a string

Greetings,

I want to echo a string to a terminal in a bash script which contains the output of a command which gives multiple lines if executed in bash. Sadly the linebreaks are lost. How can I preserve them?

command output is

line one
line two

My script looks like

...
string=`command`
...
echo $string
...

script output is

line one line two

Thanks!
Viv

edit: Ok, I'm stupid. I can just execute the command where I need its output. Now script is a bit inconsistent but it works.

Last edited by V for Vivian (2009-08-28 19:03:47)


YES WE CAN
(but that doesn't necessarily mean we're going to)

Offline

#2 2009-08-28 19:23:55

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: [solved] bash: multiple lines in a string

quoting the variable when echoing it might help.  I did this little test:

$ tempvar="hi there
> ho there"
$ echo $tempvar
hi there ho there
$ echo "$tempvar"
hi there
ho there
$

Offline

Board footer

Powered by FluxBB