Programming and Scripting :: How to assing a line break to a variable in bash?



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...

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.

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

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

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.

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

So it must be somewhere else...

Next Page...
original here.