file content into unix variable with newlines

Posted by Hugo on Stack Overflow See other posts from Stack Overflow or by Hugo
Published on 2010-05-07T14:33:29Z Indexed on 2010/05/07 14:38 UTC
Read the original article Hit count: 146

Filed under:

I have a text file test.txt with the following content:
text1
text2

And I want to assign the content of the file to a UNIX variable but when I do this:

testvar=$(cat test.txt)

echo $testvar the reult is:

text1 text2

instead of

text1
text2

Can someone suggest me a solution for this?

© Stack Overflow or respective owner

Related posts about unix