[mdlug] Scripting - Newlines getting clobbered?

Carl T. Miller carl at carltm.com
Wed Dec 26 15:18:39 EST 2007


Wojtak, Greg wrote:
> I am trying to read a multi-line file into a variable, and the lines are
> getting concatenated together in one big line.  So a file that contains
>
> line 1
> line 2
> line 3
> line d
> line 6
>
> would look like line 1 line 2 line 3 line d line 6 when I do:
>
> VAR=`cat data`
> echo $VAR
>
> Any ideas how to keep the newline inside of variables?

Sure, just use quotes, like this:

VAR="`cat data`"
echo "$VAR"

c





More information about the mdlug mailing list