Looping over two variables in tandem (ie. over pairs) in shell
<p>I have a list of files in ids1. Example </p>

<pre><code>s1_aaa
s1_aab
s1_aac
</code></pre>

<p>I want to submit jobs for these files using sbatch: I use</p>

<pre><code>for x in `cat ids1`;do sbatch batch_job.sbatch $x ;done 
</code></pre>

<p>This works fine.</p>

<p>Now I try for 2 variables in the for loop. Example I have another file ids2 like </p>

<pre><code>s2_aaa
s2_aab
s2_aac
</code></pre>

<p>I want to submit jobs for files in <code>ids1</code> and <code>ids2</code> simultaneously i.e. pairs (s1_aaa,s2_aaa), (s1_aab,s2_aab), (s1_aac,s2_aac) and so on. When I try </p>

<pre><code>for x,y in `cat ids1;cat ids2`;do sbatch batchjob.sbatch $x $y ;done
</code></pre>

<p>I get the error </p>

<pre><code>-bash: `x,y': not a valid identifier
</code></pre>

<p>What am I doing wrong?</p>