title: Pass command line arguments via sbatch
body: <p>Suppose that I have the following simple bash script which I want to submit to a batch server through SLURM:</p>
  
  <pre><code>#!/bin/bash
  
  #SBATCH -o "outFile"$1".txt"
  #SBATCH -e "errFile"$1".txt"
  
  hostname
  
  exit 0
  </code></pre>
  
  <p>In this script, I simply want to write the output of <code>hostname</code> on a textfile whose full name I control via the command-line, like so:</p>
  
  <pre><code>login-2:jobs$ sbatch -D `pwd` exampleJob.sh 1
  Submitted batch job 203775
  </code></pre>
  
  <p>Unfortunately, it seems that my last command-line argument (1) is not parsed through sbatch, since the files created do not have the suffix I'm looking for and the string "$1" is interpreted literally:</p>
  
  <pre><code>login-2:jobs$ ls
  errFile$1.txt  exampleJob.sh outFile$1.txt
  </code></pre>
  
  <p>I've looked around places in <a href="https://stackoverflow.com/questions/24508040/use-bash-variable-within-slurm-sbatch-script">SO</a> and <a href="https://computing.llnl.gov/linux/slurm/sbatch.html#lbAF" rel="noreferrer">elsewhere</a>, but I haven't had any luck. Essentially what I'm looking for is the equivalent of the <code>-v</code> switch of the <code>qsub</code> utility in Torque-enabled clusters.</p>
  
  <p><strong>Edit</strong>: As mentioned in the underlying comment thread, I solved my problem the hard way: instead of having one single script that would be submitted several times to the batch server, each with different command line arguments, I created a "master script" that simply echoed and redirected the same content onto different scripts, the content of each being changed by the command line parameter passed. Then I submitted all of those to my batch server through <code>sbatch</code>. However, this does not answer the original question, so I hesitate to add it as an answer to my question or mark this question solved.</p>