views:

57

answers:

1

I'm trying to capture a block of text into a variable, with newlines maintained, then echo it.

However, the newlines don't seemed to be maintained when I am either capturing the text or displaying it.

Any ideas regarding how I can accomplish this?

Example:

#!/bin/bash

read -d '' my_var <<"BLOCK"
this
is
a
test
BLOCK

echo $my_var

Output:

this is a test

Desired output:

this

is

a

test

+4  A: 
echo "$my_var"
KennyTM
Awesome, thanks!
EmpireJones
Delightfully laconic.
Tim Post