Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Greg Wooledge 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: Mon, 30 Nov 2015 08:29:09 -0500 Lines: 12 Approved: bug-bash@gnu.org Message-ID: References: <70266BC6-C65A-4D95-B7C1-2F63F3C45DEF@qq.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1448890189 15009 208.118.235.17 (30 Nov 2015 13:29:49 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: ziyunfei <446240525@qq.com> Envelope-to: bug-bash@gnu.org Content-Disposition: inline In-Reply-To: <70266BC6-C65A-4D95-B7C1-2F63F3C45DEF@qq.com> User-Agent: Mutt/1.4.2.3i X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 139.137.100.1 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11934 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.