header image
[ # ] echo removes \n from commands
January 4th, 2011 under Linux

I wanted to send an email containing a folder listing. I noticed that when I do

1
2
text=`ls -lh $folder`<br />
echo $text
text=`ls -lh $folder`<br />
echo $text

the newlines in the variables are gone. Also when I force to interpret the with the option

To get the newline back the variable has to expanded within quotes.

1
echo -e "$text"
echo -e "$text"

for more info see here