Search code examples
bashgnu-parallel

How to send arguments to bash script in GNU parallel


I want to use GNU parallel to execute some commands in parallel, but I don't know how to send the argument to my bash scripts.

My bash_script.sh:

scp $1.zip xxx@1.com:~/
scp $1.zip xxx@2.com:~/
scp $1.zip xxx@3.com:~/
scp $1.zip xxx@4.com:~/
scp $1.zip xxx@5.com:~/

I can send the argument to the bash_script and execute it in sequence.

bash bash_script.sh argument

but how to do it in parallel?

parallel -a bash_script argument

Solution

  • bash_script.sh

    parallel scp "$1" xxx@{}.com: ::: {1..5}
    

    Usage:

    bash bash_script.sh argument