bug-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] make function local


From: Chet Ramey
Subject: Re: [Help-bash] make function local
Date: Sun, 19 Apr 2015 19:53:29 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 4/17/15 6:27 PM, Linda Walsh wrote:
> 
> 
> Eduardo A. Bustamante López wrote:
>> Well, if your scripts are so simple, why use local functions at all?
> ---
>     Cleanliness, Hygiene...

Please, let's not have this argument again.  I think you're all using the
term `local function' to mean different things.

You seem to be using the term to describe one-time-use functions (they're
almost lambdas, but they have names).  If you define a function within
another function's body, have it unset itself when it executes, and call
it only from within the function where it's defined, you have something
very close to one-time-use functions with function-only scope.

However you use them, they share the name namespace as every other defined
function, regardless of whether or not they are defined as part of the body
of another function.  If you had a function defined in the global scope
with the same name as your one-time-use function, it would be removed when
the one-time-use function was declared.  I think this is what Greg and
Eduardo mean, and in this sense they are correct: bash doesn't have local
functions with separate namespaces from other defined functions.

That's the difference: if you're careful with naming and rigorous about
your calling conventions, your one-time-use functions are about as close
as you can get to local functions in bash, but you have to pay attention
to the declaration's side effects.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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