Having a hard time formulating this question. Suggestions welcome.
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.
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:
chmod +x myprog.py
./myprog.py arg1 arg2 arg3
But I want to have many possible values for arg1, arg2, and arg3. So I set up a text table in readparas.txt:
arg1_1 arg2_1 arg3_1
arg1_2 arg2_2 arg3_2
arg1_3 arg2_3 arg3_3
...
I want to read in the first line and run myprog. Then go to the second line and run myprog, etc.
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.
To complicate things, I want to do this using a bash script. The following was mostly taken from Sergey Mashchenko at SharcNet:
#!/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 < readparas.txt
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?
EDIT
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).
#!/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 < readparas.txt
It gives me this error:
-bash: ./epi_cmd.sh: usr/bin/bash: bad interpreter: No such file or directory
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?
EDIT 2
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.
This runs but returns another error:
#!/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 < readparas.txt
The error message is:
./epi_cmd.sh: line 6: i: command not found
Then says all of the arguments are unrecognized.
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....