title: How to preserve line breaks when storing command output to a variable?
body: <p>I’m using bash shell on Linux.  I have this simple script …</p>
  
  <pre><code>#!/bin/bash
  
  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
  </code></pre>
  
  <p>However, when I run this script</p>
  
  <pre><code>./temp.sh
  </code></pre>
  
  <p>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.</p>
  
  <p>How do I store the output of the command to a variable and preserve the line breaks/carriage returns?</p>