douyou
douyou

Reputation: 85

run loop with gnu parallel and pass in a variable

I need to run a bash function for each element in a dir via gnu parallel. I need to access a evn variable for this function. how do I pass in it. for example following code in a shell script. I have a variable DIRS=/folder/log. how do I pass 'DIRS' to function readfile_ . thanks in advance.

export SHELL=$(type -p bash)
function readfile_ {do something}

export -f readfile_ 
ls -d */ | grep -v errlogs |  parallel readfile_ 

Upvotes: 3

Views: 2694

Answers (1)

douyou
douyou

Reputation: 85

I got it.

refer to http://www.gnu.org/software/parallel/parallel_tutorial.html#Transfer-environment-variables-and-functions

DIRS=/folder/log
export DIRS
ls -d */ | grep -v errlogs |  parallel --env DIRS readfile_ 

Upvotes: 2

Related Questions