Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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_ 
like image 424
douyou Avatar asked Mar 24 '26 18:03

douyou


1 Answers

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_ 
like image 67
douyou Avatar answered Mar 26 '26 14:03

douyou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!