help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Closure concept in bash


From: Bob Proulx
Subject: Re: [Help-bash] Closure concept in bash
Date: Mon, 30 Jan 2012 20:50:29 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

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.

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.

Bob



reply via email to

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