user7169125 user7169125 - 19 days ago 5
Bash Question

Script to run C++ code with different user input

I have a c++ executable file 'Score' that takes as input two user defined 'values'.
These values are some data in txt files. I run the program and save the output to a text file like this :

./Score data1.txt data2.txt >outdata1data2.txt


Because I need to run this for many times would be possible to create a shell bash script that does this automatically something like :

./Score data1.txt data3.txt >outdata1data3.txt
./Score data1.txt data4.txt >outdata1data4.txt


and so on..

The names of the data are all different and all in the same directory as the executable file.
My knowledge in C++ is very limited and any help would be appreciated

Answer

It is definitely possible. You will probably want to write a shell script similar to this:

#!/bin/bash
for filename1 in /*.txt; do
  for filename2 in /*.txt; do
    ./Score "$filename1" "$filename1" > "out$filename1$filename2"
  done
done
Comments