bug-bash
[Top][All Lists]
Advanced

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

Re: [bash 4.2] `declare -g' bug?


From: Chet Ramey
Subject: Re: [bash 4.2] `declare -g' bug?
Date: Thu, 17 Feb 2011 19:45:20 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7

On 2/16/11 5:07 AM, Clark J. Wang wrote:
> See following script result:
> 
> bash# cat declare-g.sh
> #!/bin/bash
> 
> var=global
> 
> f1()
> {
>     declare var=local
> 
>     f2
>     echo 3.$var
> }
> 
> f2()
> {
>     declare -g var
> 
>     echo 1.$var
>     var=global-changed
>     echo 2.$var
> }
> 
> f1
> echo 4.$var
> bash# /usr/local/bash-4.2.0/bin/bash declare-g.sh
> 1.local
> 2.global-changed
> 3.global-changed
> 4.global
> bash#
> 
> I think the right result should be:
> 
> 1.global
> 2.global-changed
> 3.local
> 4.global-changed

The -g option exists solely to create variables at the global scope.  The
intent is that functions be able to declare global variables with
attributes if they desire.  It doesn't change the scoping rules or
variable resolution behavior.

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]