title: Bash: how to join a specific number of arguments
body: <p>Having a hard time formulating this question. Suggestions welcome.</p>
  
  <p>My overall goal is to read in one line of the file at a time, and run a python program using those arguments, then go to the next line.</p>
  
  <p>For example, say my program is myprog.py and it takes 3 input parameters. If I were using the command line alone, I would do this:</p>
  
  <pre><code>chmod +x myprog.py
  ./myprog.py arg1 arg2 arg3
  </code></pre>
  
  <p>But I want to have many possible values for arg1, arg2, and arg3. So I set up a text table in readparas.txt:</p>
  
  <pre><code>arg1_1 arg2_1 arg3_1
  arg1_2 arg2_2 arg3_2
  arg1_3 arg2_3 arg3_3
  ...
  </code></pre>
  
  <p>I want to read in the first line and run myprog. Then go to the second line and run myprog, etc.</p>
  
  <p>The problem is some of the arguments go together. For example, arg2 and arg3 may be different settings of a single parameter. So arg2 and arg3 would need to be treated as one argument.</p>
  
  <p>To complicate things, I want to do this using a bash script. The following was mostly taken from Sergey Mashchenko at SharcNet:</p>
  
  <pre><code>#!/bin/bash
  i = 0
  while read arg1 arg2 arg3
     do
     i = $(($i+1))
     mkdir RUN$i
     cd RUN$i
     ./myprog.py $arg1 $arg2 $arg3 #need groups of args here
     cd ..
     done &lt; readparas.txt
  </code></pre>
  
  <p>I have more than three arguments, though, and groups of them need to be joined together. For example, suppose I have 8 arguments. I want to 'group' arguments 2 through 4 and arguments 6 through 8. How can I do that?</p>
  
  <p>EDIT</p>
  
  <p>On the suggestion by @chepner, I tried the following (yes there are actually 19 arguments, and I want to join f through j and k through s). </p>
  
  <pre><code>#!/usr/bin/bash #with thanks to rici for pointing this out
  
  i=0
  while read a b c d e f g h i j k l m n o p q r s
      do
      i = $(($i+1))
      mkdir RUN$i
      cd RUN$i
      ./my_prog "$a" "$b" "$c" "$d" "$e" "$f$g$h$i$j" "$k$l$m$n$o$p$q$r$s"
      cd ..
      done &lt; readparas.txt 
  </code></pre>
  
  <p>It gives me this error:</p>
  
  <pre><code>-bash: ./epi_cmd.sh: usr/bin/bash: bad interpreter: No such file or directory
  </code></pre>
  
  <p>So does the commented suggestion by @redxef so I'm not sure if one of them is right, or if I've messed something else up. I know myprog.py runs when I run it through the command line (without bash, as in my example at the top). There must be an error in the bash?</p>
  
  <p>EDIT 2</p>
  
  <p>Okay, I fixed the bash error by realizing that I really did have a file that wasn't being read properly, and by realizing that I was defining 'i' twice.</p>
  
  <p>This runs but returns another error:</p>
  
  <pre><code>#!/usr/bin/bash
  
  i=0
  while read a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1
      do
      i = $(($i+1))
      mkdir RUN$i
      cd RUN$i
      ../myprog.py $a1 $b1 $c1 $d1 $e1 $f1\ $g1\ $h1\ $i1\ $j1 $k1\ $m1\ $n1\ $o1\ $p1\ $q1\ $r1\ $s1 
      cd ..
      done &lt; readparas.txt 
  </code></pre>
  
  <p>The error message is:</p>
  
  <pre><code>./epi_cmd.sh: line 6: i: command not found
  </code></pre>
  
  <p>Then says all of the arguments are unrecognized.</p>
  
  <p>I know there were requests for output, but that wouldn't fit here. I'm writing a .json file and two .txt files using myprog.py, and myprog.py itself is about 200 lines long....</p>