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?

1 Answer 1

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*
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.