How to preserve line breaks when storing command output to a variable?

I’m using bash shell on Linux. I have this simple script …


TEMP=`sed -n """Starting deployment of"'/,/'"Failed to start context"'/p' "/usr/java/jboss/standalone/log/server.log" | tac | awk """Starting deployment of"'/ {print;exit} 1' | tac`
echo $TEMP

However, when I run this script


all the output is printed without the carriage returns/new lines. Not sure if its the way I’m storing the output to $TEMP, or the echo command itself.

How do I store the output of the command to a variable and preserve the line breaks/carriage returns?

2 Answers

Leave a Comment