Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign variables in gnu parallel?

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.

like image 304
nachocab Avatar asked Oct 17 '25 14:10

nachocab


1 Answers

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
like image 162
Ole Tange Avatar answered Oct 19 '25 13:10

Ole Tange