title: How to redirect both stdout and stderr to a file from within a bash script?
body: <p>I want to add a command to my bash script that directs all stderr and stdout to specific files. From <a href="https://stackoverflow.com/questions/876239/how-to-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash">this</a> and many other sources, I know that from the command line I would use:</p>
  
  <pre><code>/path/to/script.sh &gt;&gt; log_file 2&gt;&gt; err_file
  </code></pre>
  
  <p>However, I want something inside my script, something akin to these slurm flags:</p>
  
  <pre><code>#!/bin/bash
  #SBATCH -o slurm.stdout.txt # Standard output log
  #SBATCH -e slurm.stderr.txt # Standard error log
  
  &lt;code&gt;
  </code></pre>
  
  <p>Is there a way to direct output from within a script, or do I need to use <code>&gt;&gt; log_file 2&gt;&gt; err_file</code> every time I call the script? Thanks</p>