4

I have a bash loop where I am passing variables to a script. I want to run these in parallel with GNU parallel

for FILE_NAME in FILE1 FILE2 FILE3; 
do
    ./SCRIPT -n $FILE_NAME
done

where I want the scripts to run in parallel as follows:

     ./SCRIPT -n FILE1
     ./SCRIPT -n FILE2
     ./SCRIPT -n FILE3

I am trying to use the GNU parallel command because it has been suggested a lot on here, but I am confused about where to put the parallel command if I am passing a variable to the script.

I have tried turning the FILE1 FILE2 FILE3 into a list:

parallel -a $FILE_LIST ./SCRIPT -n $FILE_NAME
for FILE_NAME in FILE1 FILE2 FILE3; 
do
    parallel ./SCRIPT -n $FILE_NAME
done

Do you have any suggestions?

Daniel
  • 11,332
  • 9
  • 44
  • 72
Maria
  • 73
  • 6

1 Answers1

2

Try like this:

parallel ./SCRIPT -n {} ::: FILE1 FILE2 FILE3

Or, more succinctly if your files are really named like that:

parallel ./SCRIPT -n {} ::: FILE*
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432