title: Shell - Write variable contents to a file
body: <p>I would like to copy the contents of a variable (here called <code>var</code>) into a file.</p>
  
  <p>The name of the file is stored in another variable <code>destfile</code>. </p>
  
  <p>I'm having problems doing this. Here's what I've tried:</p>
  
  <pre><code>cp $var $destfile
  </code></pre>
  
  <p>I've also tried the same thing with the dd command... Obviously the shell thought that <code>$var</code> was referring to a directory and so told me that the directory could not be found. </p>
  
  <p>How do I get around this?</p>