title: Using variables inside a bash heredoc
body: <p>I'm trying to interpolate variables inside of a bash heredoc:</p>
  
  <pre><code>var=$1
  sudo tee "/path/to/outfile" &gt; /dev/null &lt;&lt; "EOF"
  Some text that contains my $var
  EOF
  </code></pre>
  
  <p>This isn't working as I'd expect (<code>$var</code> is treated literally, not expanded).</p>
  
  <p>I need to use <code>sudo tee</code> because creating the file requires sudo.  Doing something like:</p>
  
  <pre><code>sudo cat &gt; /path/to/outfile &lt;&lt;EOT
  my text...
  EOT
  </code></pre>
  
  <p>Doesn't work, because <code>&gt;outfile</code> opens the file in the current shell, which is not using sudo.</p>