title: Why does rewriting a file with "envsubst <file >file" leave it empty?
body: <p>I need to put some environment variables values to file.</p>
  
  <pre><code>cat file
  # $VAR
  
  echo $VAR
  # text
  </code></pre>
  
  <p>When I do <code>envsubst '$VAR $VAR' &lt; file &gt; file</code> file becomes empty. To resolve this issue I use <code>envsubst '$VAR $VAR' &lt; file | tee file 2&gt;&amp;1 &gt;/dev/null</code>. But sometimes it doesn't work, I mean file becomes empty. The first question is why sometimes file becomes empty and the second is what is the TRUE Unix way to put env vars to file in Linux and *BSD and MacOS ?</p>