19

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 ?

p4guru
  • 1,400
  • 2
  • 19
  • 25

2 Answers2

27

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
Thirupathi Thangavel
  • 2,418
  • 3
  • 29
  • 49
9

If you insist on using GNU Parallel:

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

b() {
  echo "download b"
  wget fileB
}
export -f a
export -f b
parallel ::: a b

If you need read access to variables in the shell you can either export the variables or use env_parallel.

Ole Tange
  • 31,768
  • 5
  • 86
  • 104