Append output from both stdout and stderr of every command of a bash script to file
<p>Here</p>

<p><a href="https://stackoverflow.com/a/876267/1579327">https://stackoverflow.com/a/876267/1579327</a></p>

<p>I learned how to do that for a single command <code>cmd</code> appending output to <code>file.txt</code></p>

<pre><code>cmd &gt;&gt;file.txt 2&gt;&amp;1
</code></pre>

<p>But my script contains many statements and commands.</p>

<p>And I would like to avoid appending <code>&gt;&gt;file.txt 2&gt;&amp;1</code> to every line.</p>

<p>Is there a directive to let me to do that by default for every subsequent command?</p>

<hr>

<p>Side note: I'm looking for a solution suitable also for MacOs X's bash</p>