Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ [1] 2 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: How to assing a line break to a variable in bash?< Next Oldest | Next Newest >
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Oct. 22 2006,16:14 QUOTE

I need to do this:
Code Sample
LIST=$LIST$ITEM[B]$LINEBREAK[/B]


I've tried even to use 'echo' to add line break but none has worked.
I've also searched Google already...


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Oct. 22 2006,17:18 QUOTE

There are a few ways to do it, depending on how you want to use the variable.

One way is:
Code Sample
LIST=`echo -e "$LIST$ITEM\n"`


Another way is to use a different type of separator, such as a space or comma, when setting the variable, and then using tr to replace the separator with a newline when the variable is called.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Oct. 22 2006,19:49 QUOTE

I've tried that before. Doesn't wotk. :(

I tried this also:
Code Sample
BREAK=`echo -e "\n"`


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: Oct. 22 2006,21:07 QUOTE

You can try this, I just did and it works:

Code Sample
LIST="This and "
ITEM="That"
LINEBREAK="
"
TEST1=$LIST$ITEM[b]$LINEBREAK[/b]
TEST2="$LIST$ITEM[b]$LINEBREAK[/b]"

echo $TEST1
echo $TEST2


The second test succeeds because of the quotes, the first one fails by putting everything on one line.  You need the quotes when you assign the variable.
Back to top
Profile PM 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Oct. 22 2006,23:03 QUOTE

I had those quotes on my script.
But that
Code Sample
BREAK="
"
.. still didn't worked.

So it must be somewhere else...


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
10 replies since Oct. 22 2006,16:14 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ [1] 2 3 >/
reply to topic new topic new poll
Quick Reply: How to assing a line break to a variable in bash?

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code