Tricky bash to try and run the program with different parameters
I want to run a program multiple times with different parameters and then put the results in files that use the parameters in their names. This is what I came up with:
#!/bin/bash
for i in 'seq 1 5';
do
for j in 'seq 1 8';
do
for m in 'seq 1 8';
do
./program -s i -v j -k m ../input_files/input_file1.txt < results_ijm.txt
done
done
done
This does not work. It says "no results_ijm.txt file" .... I know what - I want it to create this file implicitly.
Otherwise, I also doubt that it will assign the ijm in the filename correctly - how does it know if I want VARIABLES ijm .... or just characters? This is ambiguous.
source to share
- You must use variables
$i
,$j
,$m
etc. - Better to use the construct
((...))
in BASH.
In BASH, you can:
#!/bin/bash
for ((i=1; i<=5; i++)); do
for ((j=1; h<=8; j++)); do
for ((m=1; m<=8; m++)); do
./program -s $i -v $j -k $m ../input_files/input_file1.txt > "results_${i}${j}${m}.txt"
done
done
done
source to share
Two problems. As I mentioned in the comments, your arrow is back. We want the program output to go from stdout to a file, so turn that thing around. Second, variables get a dollar sign in front of them when used ... so it won't be ambiguous.
Edited to add: third, use backreferences instead of single quotes for seq 1 5
you want the results of this command, not the text "seq 1 5". Thanks @PSkocik
#!/bin/bash
for i in `seq 1 5`;
do
for j in `seq 1 8`;
do
for m in `seq 1 8`;
do
./program -s $i -v $j -k $m ../input_files/input_file1.txt > results_${i}${j}${m}.txt
done
done
done
source to share