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


Groups > gnu.bash.bug > #11948

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

Path csiph.com!au2pb.net!feeder.erje.net!2.us.feeder.erje.net!news.glorb.com!usenet.stanford.edu!not-for-mail
From Chet Ramey <chet.ramey@case.edu>
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 Sat, 5 Dec 2015 15:18:09 -0500
Organization ITS, Case Western Reserve University
Lines 20
Approved bug-bash@gnu.org
Message-ID <mailman.1467.1449346701.31583.bug-bash@gnu.org> (permalink)
References <70266BC6-C65A-4D95-B7C1-2F63F3C45DEF@qq.com>
Reply-To chet.ramey@case.edu
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1449346702 17259 208.118.235.17 (5 Dec 2015 20:18:22 GMT)
X-Complaints-To action@cs.stanford.edu
Cc chet.ramey@case.edu
To ziyunfei <446240525@qq.com>, bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
In-Reply-To <70266BC6-C65A-4D95-B7C1-2F63F3C45DEF@qq.com>
X-Mirapoint-Virus-RAPID-Raw score=unknown(0), refid=str=0001.0A020205.56634683.0008,ss=1,re=0.000,fgs=0, ip=40.133.163.73, so=2015-08-12 04:07:17, dmn=2011-05-27 18:58:46
X-Mirapoint-Loop-Id 813b9b1e31319ef88fb89438deb4753b
X-Junkmail-Whitelist YES (by domain whitelist at mpv3-2015.case.edu)
X-Mirapoint-Virus-RAPID-Raw score=unknown(0), refid=str=0001.0A020202.56634683.00C6,ss=1,re=0.000,fgs=0, ip=40.133.163.73, so=2015-08-12 04:07:17, dmn=2011-05-27 18:58:46
X-Mirapoint-Loop-Id 2b9a5e9453079bf2bcc7616ff05ae9f4
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy]
X-Received-From 129.22.103.194
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.14
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:11948

Show key headers only | View raw


On 11/27/15 10:18 PM, ziyunfei wrote:
> $ ksh -c 'foo() { readonly a=(1);echo a=$a; }; foo; echo a=$a'
> a=1
> a=1
> $ bash -c 'foo() { readonly a=(1);echo a=$a; }; foo; echo a=$a' # a becomes a local variable
> a=1
> a=

Thanks for the report.  I agree that this is a bug.  `readonly' and
`export' should not create local variables when invoked within a function;
only declare/local/typeset should create local variables.

This will be fixed in the next release of bash.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

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 Chet Ramey <chet.ramey@case.edu> - 2015-12-05 15:18 -0500

csiph-web