title: QSUB: Specify output and error files for each task in Job Array
body: <p>Hopefully this is not a dublicate and also not just a problem of our cluster's configuration...</p>
  
  <p>I am submitting a job array to a cluster using <code>qsub</code> with the following command:</p>
  
  <pre><code>qsub -q QUEUE -N JOBNAME -t 1:10 -e ${ERRFILE}_$SGE_TASK_ID /path/to/script.sh
  </code></pre>
  
  <p>where </p>
  
  <pre><code>ERRFILE=/home/USER/somedir/errors.
  </code></pre>
  
  <p>The idea is to specify an error file (also analogously the output file) that also contains the task ID from within the job array.</p>
  
  <p>So far I have learned that the line</p>
  
  <pre><code>#$ -e ${ERRFILE}_$SGE_TASK_ID
  </code></pre>
  
  <p>inside the script.sh, does not work, because it is a comment and not evaluated by bash. My first line does not work however because <code>$SGE_TASK_ID</code> is only set AFTER the job is submitted.<br>
  I read <a href="https://stackoverflow.com/questions/26479277/pbspro-qsub-output-error-file-directed-to-path-with-jobid-in-name">here</a> that escaping the evaluation of <code>$SGE_TASK_ID</code> (in that link it's PBS' <code>$PBS_JOBID</code>, but a similar problem) should work, but when I tried </p>
  
  <pre><code>qsub -q QUEUE -N JOBNAME -t 1:10 -e ${ERRFILE}_\$SGE_TASK_ID /path/to/script.sh
  </code></pre>
  
  <p>it did not work as expected.</p>
  
  <p>Am I missing something obvious? Is it possible to use <code>$SGE_TASK_ID</code> in the name of an error file (the automatic naming of error files does that, but I want to specify the directory and if possible the name, too)?</p>
  
  <p>Some additional remarks:</p>
  
  <ul>
  <li>I am using the <code>-cwd</code> option for <code>qsub</code> inside script.sh, but that is NOT where I want my error files to be stored.</li>
  <li>I have next to no control over how the cluster works and no root access (wouldn't know what I could need it for in this context but anyway...).</li>
  <li>Apparently our cluster does not use PBS.</li>
  <li>Yes my scripts are all executable and where applicable started with <code>#!/bin/bash</code> (I also specified the use of bash with the <code>-S /bin/bash</code> option for qsub).</li>
  <li>There seems to be a solution <a href="https://stackoverflow.com/questions/9096959/how-to-specify-error-log-file-and-output-file-in-qsub">here</a>, but I am not quite sure how that works and it also appears to be using PBS. If that answer DOES apply to my question and I misunderstood it, please let me know.</li>
  </ul>
  
  <p>I would appreciate any hint into the right direction.
  Thank You!</p>