parallel call multiple bash functions

p4guru picture p4guru · Dec 21, 2015 · Viewed 10.4k times · Source

I have read the example at http://www.gnu.org/software/parallel/man.html#example__calling_bash_functions however, is it possible to use gnu parallel to call 2 functions which do not have any variables you pass to them ?

example

a() {
  echo "download a"
  wget fileA
}

b() {
  echo "download b"
  wget fileB
}

and use parallel to call both functions a & b ?

Answer

Thirupathi Thangavel picture Thirupathi Thangavel · Dec 21, 2015

Run them in background. And then wait for them to complete.

a() {
  echo "download a"
  wget fileA
}

b() {
  echo "download b"
  wget fileB
}

a &
b &
wait # waits for all background processes to complete