bug-bash
[Top][All Lists]
Advanced

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

Re: Local variables overriding global constants


From: Chris F.A. Johnson
Subject: Re: Local variables overriding global constants
Date: Wed, 3 Apr 2013 03:43:32 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Wed, 3 Apr 2013, Nikolai Kondrashov wrote:

Hi everyone,

It seems Bash 4.2.37 doesn't allow functions to redefine global constants
locally, yet it allows redefining constants local to calling functions.
Is this as supposed to be, or is it a bug?

I.e. this:

   bash -c 'declare -r v; a() { declare -r v; }; a'

Results in:

   bash: line 0: declare: v: readonly variable

   It doesn't work because you are trying to redefine an existing
   readonly variable.

While this works:

   bash -c 'a() { declare -r v; }; b() { declare -r v; a; }; b'

   It works because both instances are local to a function and don't
   exist outside their own functions.

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



reply via email to

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