Inheriting Environment Variables Using GNU Parallel

I would like to inherit environment variables in GNU Parallel. I have several “scripts” (actually just lists of commands designed for use with GNU Parallel) with hundreds of lines, each of which calls different external programs. However, this external program (out of my control) requires that several environment variables be set before they are run.

Setting / exporting locally does not help, and I see no way to add this information to the profile.

The documentation doesn't seem to have anything like this, and similar SO pages suggest wrapping the command in a script. However, this seems like an inelegant decision. Is there a way to export the current environment, or perhaps specify the required variables in a script?

Thank!

+5
source share
1 answer

This works for me:

FOO="My  brother  12\"  records"
export FOO
parallel echo 'FOO is "$FOO" Process id $$ Argument' ::: 1 2 3

To make it work for remote connections (via ssh), you need to specify a variable to extend the shell. parallel --shellquotecan help you with this:

parallel -S server export FOO=$(parallel --shellquote ::: "$FOO")\;echo 'FOO is "$FOO" Process id $$ Argument' ::: 1 2 3

If this does not solve your problem, consider an example that does not work.

- Change -

See --envintroduced in version 20121022

- Change -

Look env_parallelintroduced in 20160322.

+6
source

All Articles