4

I want to assign a variable in the command that I pass to parallel:

parallel "my_variable={}_33; echo $my_variable" ::: a b c

The output should be:

# a_33
# b_33
# c_33

Of course, this is just a toy example. In the real example I want to do other things with that variable.

nachocab
  • 13,328
  • 21
  • 91
  • 149

1 Answers1

13

You are so close to solving it yourself. You just forgot that there is a difference between " and ':

parallel 'my_variable={}_33; echo $my_variable' ::: a b c

If you are doing advanced stuff, remember that you can use bash functions:

doit() {
   echo Doing it for $1
   sleep 2
   echo Done with $1
}
export -f doit
parallel doit ::: 1 2 3
Ole Tange
  • 31,768
  • 5
  • 86
  • 104