[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Closure concept in bash

From: Greg Wooledge
Subject: Re: [Help-bash] Closure concept in bash
Date: Tue, 31 Jan 2012 08:47:04 -0500
User-agent: Mutt/

On Mon, Jan 30, 2012 at 09:32:14PM -0600, Peng Yu wrote:
> > What do you mean by "closure"?
> See here for the explanation of closure.

 "In computer science, a closure (also lexical closure, function closure,
 function value or functional value) is a function together with a referencing
 environment for the non-local variables of that function.[1] A closure allows
 a function to access variables outside its typical scope."

How very bizarre.  I still don't quite understand the purpose, but I'll
set it aside for now.

Once again, what are you trying to do here?  Are you trying to launch
5 jobs at a time out of a list of 1000 jobs, where each "job" is a
bash function, and therefore is not available to GNU parallel, which
is an external program?

The obvious way to do that would be to put the function's defining code
in a file, and then source it in a shell created by GNU parallel.

$ cat myfunc
myfunc() {
  echo "\$1 is $1"
$ parallel bash -c 'source ./myfunc; myfunc "$1"' _ -- 1 2 3
$1 is 2
$1 is 1
$1 is 3

This is much cleaner and safer than trying to export a function through
the environment and simply hoping that it magically comes through.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]