Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11934

Re: An array variable created by export/readonly builtins inside a function becomes a locale variable to that function unexpectedly

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: An array variable created by export/readonly builtins inside a function becomes a locale variable to that function unexpectedly
Date 2015-11-30 08:29 -0500
Message-ID <mailman.1007.1448890189.31583.bug-bash@gnu.org> (permalink)
References <70266BC6-C65A-4D95-B7C1-2F63F3C45DEF@qq.com>

Show all headers | View raw


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.

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: An array variable created by export/readonly builtins inside a function becomes a locale variable to that function unexpectedly Greg Wooledge <wooledg@eeg.ccf.org> - 2015-11-30 08:29 -0500

csiph-web