Am 24.03.2011 02:16, schrieb nix@xxxxxxxxxxxxxxxx:
>> Hi all,
>>
>> I often use the construct of defining a function inside another
>> function. Now I discovered, that these pour into the environment, i.e.
>> if I have
>>
>> foo ()
>> {
>> bar () { }
>> }
>>
>> and I execute "foo", "bar" is now visible in my environment.
>>
>> Is there some way of making 'bar' to be local to 'foo'? Using the
>> 'local' keyword does not work :).
>>
>> I know, that in principle it is possible to explicitly 'unfunction'
>> functions, but this is not a usable way sometimes.
>>
>> Thanks for your help,
>> René
>>
>>
>
> I think localing is possibly only to variables as you know. What you're
> trying to achieve by localing 'bar' inside 'foo'?
>
Avoiding name space cluttering and also avoiding the possibility of
overwriting already existing functions or aliases.
Take for example:
bar () {
echo muh
}
...
foo () {
bar () { echo moep }
}
No after executing 'foo', 'bar' does something completely different,
which is in most cases extremely unwelcome.
- René
Attachment:
signature.asc
Description: OpenPGP digital signature