[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/1.4.2.3i |
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.
> http://en.wikipedia.org/wiki/Closure_%28computer_science%29
"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.
- Re: [Help-bash] Closure concept in bash, (continued)
- Re: [Help-bash] Closure concept in bash, Greg Wooledge, 2012/01/27
- Re: [Help-bash] Closure concept in bash, Peng Yu, 2012/01/30
- Re: [Help-bash] Closure concept in bash, Bob Proulx, 2012/01/30
- Re: [Help-bash] Closure concept in bash, Peng Yu, 2012/01/30
- Re: [Help-bash] Closure concept in bash, Bob Proulx, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Peng Yu, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Bob Proulx, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Bob Proulx, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Peng Yu, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Greg Wooledge, 2012/01/31
- Re: [Help-bash] Closure concept in bash,
Greg Wooledge <=
- Re: [Help-bash] Closure concept in bash, Chet Ramey, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Peng Yu, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Greg Wooledge, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Peng Yu, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Bob Proulx, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Peng Yu, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Dan Douglas, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Chet Ramey, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Ken Irving, 2012/01/31
- Re: [Help-bash] Closure concept in bash, Chet Ramey, 2012/01/31