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

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

#!/bin/bash

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

However, when I run this script

./temp.sh

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
2

Leave a Comment