[Top][All Lists]

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

Re: [Help-bash] Closure concept in bash

From: Peng Yu
Subject: Re: [Help-bash] Closure concept in bash
Date: Mon, 30 Jan 2012 22:12:57 -0600

On Mon, Jan 30, 2012 at 9:50 PM, Bob Proulx <address@hidden> wrote:
> Peng Yu wrote:
>> See here for the explanation of closure. It is a concept in
>> programming language. Most JavaScript code uses this property
>> extensively. This feature (or at least something similar to it) will
>> be also useful to bash in the case of "export -f func".
> Scoping in the shell is currently very simple.  At a first order of
> approximation variables are either global or local and global variables
> are either exported or not.
> The shell is very good at what it does.  If you want to do more than
> what it does then you should use a different language such as awk,
> perl, python, or ruby.  All of those have complex data structures
> available to them.

Please take a look at the example code that uses gnu parallel in the
first email. Unfortunately, using other languages can not solve this
problem. (Please correct me, it is the not the case.)

> If the shell were to adopt every good idea that anyone ever thought up
> then it wouldn't be the shell anymore but would then be perl.
>> Otherwise, all the variables used in func has to be manually
>> exported, which is very inconvenient.
> Look at the documentation for set -a.
>              -a   Automatically mark variables and functions which are
>                   modified or created for export to the environment
>                   of subsequent commands.
> *I* never want that feature.  I have been known to rewrite code that
> uses it.  But it seems like the feature you want.

"set -a" at least makes the example code in the first email work. But
the document for "-a" doesn't make sense to me. What does "mark" mean?


reply via email to

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