title: bash print escaped file contents
body: <p>I'm trying to print the file contents with escaped double quotes.</p>
  
  <pre><code># read file contents from ${filename}
  # - escape double quotes
  # - represent newlines as '\n' 
  # print the result
  echo "my file contents: \"${out}\""
  </code></pre>
  
  <p>So for example if my file is</p>
  
  <pre><code>&lt;empty line&gt;
  console.log("hello, world");
  &lt;empty line&gt;
  </code></pre>
  
  <p>it should print</p>
  
  <pre><code>my file contents: "\nconsole.log(\"hello, world\");\n"
  </code></pre>
  
  <p>I was trying to use printf with %q format specifier, but had problems that it removes the trailing spaces.</p>