Re: Question if bug: declaration of an associative array within a function

2010-06-15 Thread Chet Ramey
On 6/15/10 5:22 PM, Greg Wooledge wrote:

> `declare' has the side effect of making things local to a function, if
> it is used within a function.  There is currently no way to create a
> global associative array while inside a function; you'd have to do it
> outside the function.
> 
> Chet has said, I think, that he might consider a `global' (or similar)
> keyword at some point in the future.

Actually, it would be a `-g' option to declare, and that will probably
get in there.

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



Re: Question if bug: declaration of an associative array within a function

2010-06-15 Thread Greg Wooledge
On Tue, Jun 15, 2010 at 01:21:51PM +0200, Rainer Rehak wrote:
> Hey there,
> is it a bug, that the declaration of an associative array within a
> function does not survive till after the function, with primitive
> variables on the other hand that concept works well.

`declare' has the side effect of making things local to a function, if
it is used within a function.  There is currently no way to create a
global associative array while inside a function; you'd have to do it
outside the function.

Chet has said, I think, that he might consider a `global' (or similar)
keyword at some point in the future.



Re: Question if bug: declaration of an associative array within a function

2010-06-15 Thread Chris F.A. Johnson
On Tue, 15 Jun 2010, Rainer Rehak wrote:

> Hey there,
> is it a bug, that the declaration of an associative array within a
> function does not survive till after the function, with primitive
> variables on the other hand that concept works well.

   It's not a bug. It's an unfortunate side effect from 'declare'
   being a duplicate of the (non-standard) typeset builtin.

   If would be much more useful (and semantically accurate), if it
   just did what its name implies, and left the 'local' builtin for
   declaring variable local to a function.

-- 
   Chris F.A. Johnson, 
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



Question if bug: declaration of an associative array within a function

2010-06-15 Thread Rainer Rehak
Hey there,
is it a bug, that the declaration of an associative array within a
function does not survive till after the function, with primitive
variables on the other hand that concept works well.

Greetings
Rainer



bug_bash_declare-A.sh
Description: Bourne shell script


signature.asc
Description: OpenPGP digital signature