[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: An array variable created by export/readonly builtins inside a funct
From: |
Greg Wooledge |
Subject: |
Re: An array variable created by export/readonly builtins inside a function becomes a locale variable to that function unexpectedly |
Date: |
Mon, 30 Nov 2015 08:29:09 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Sat, Nov 28, 2015 at 11:18:24AM +0800, ziyunfei wrote:
> $ bash -c 'foo() { readonly a=(1);echo a=$a; }; foo; echo a=$a' # a becomes a
> local variable
> a=1
> a=
"readonly" is a synonym for "declare -r", and declare (without the -g
option) always marks variables as local when used in a function.
If you want variables created in a function NOT to be local to that
function, you must skip all declarations entirely. Just create the
variable by assigning to it.