[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Local variables overriding global constants
From: |
Pierre Gaston |
Subject: |
Re: Local variables overriding global constants |
Date: |
Wed, 3 Apr 2013 11:50:13 +0300 |
On Wed, Apr 3, 2013 at 11:50 AM, Chris F.A. Johnson <chris@cfajohnson.com>wrote
>
> Still Nikolai has a point.
>>>>>
>>>>
> It's not clear why readonly variable can be overridden when the
>>>> variable is declared readonly in the scope of an englobing
>>>> function but not if it is declared readonly in the global scope.
>>>>
>>>
>>> If it's declared readonly in a function, the variable doesn't exist
>>> outside of that function, so it's not readonly there.
>>>
>>
>> I think you missed the point that "a" is called inside "b".
>> See the example below
>>
>> $ bash -c 'a() { v=2;echo "$v"; }; b () { declare -r v=1; a; echo "$v";
>>>
>>>> };
>>>> b'
>>>> bash: v: readonly variable
>>>>
>>>
>> if v doesn't exist in "a" why does it complain that it's readonly?
>>
>
> It *does* exist inside a() if a() is a child of b().
.... yes, and it's readonly, but you can redeclare it locally, something
you can't do with a readonly global variable.
- Re: Local variables overriding global constants, (continued)
- Re: Local variables overriding global constants, Nikolai Kondrashov, 2013/04/03
- Re: Local variables overriding global constants, Chris Down, 2013/04/03
- Re: Local variables overriding global constants, Nikolai Kondrashov, 2013/04/03
- Re: Local variables overriding global constants, Chris Down, 2013/04/03
- Re: Local variables overriding global constants, Pierre Gaston, 2013/04/03
- Re: Local variables overriding global constants, Pierre Gaston, 2013/04/03
- Re: Local variables overriding global constants, Nikolai Kondrashov, 2013/04/03
- Re: Local variables overriding global constants, Chris F.A. Johnson, 2013/04/03
- Re: Local variables overriding global constants, Pierre Gaston, 2013/04/03
- Re: Local variables overriding global constants, Chris F.A. Johnson, 2013/04/03
- Re: Local variables overriding global constants,
Pierre Gaston <=
- Re: Local variables overriding global constants, Chet Ramey, 2013/04/03
- Re: Local variables overriding global constants, Mike Frysinger, 2013/04/03
- Re: Local variables overriding global constants, Chet Ramey, 2013/04/03
- Re: Local variables overriding global constants, Mike Frysinger, 2013/04/04
- Re: Local variables overriding global constants, Chet Ramey, 2013/04/04
- Re: Local variables overriding global constants, Mike Frysinger, 2013/04/04
- Re: Local variables overriding global constants, Chris F.A. Johnson, 2013/04/03