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.

+3


source to share


3 answers


  • 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

      

+4


source


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

      

+3


source


./program -s i -v j -k m ../input_files/input_file1.txt < results_ijm.txt

      

I believe that a smaller character should be flipped to a larger one than for input to a file rather than from a file. I haven't worked too much with bash, but it seems logical.

0


source







All Articles