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


Groups > gnu.bash.bug > #11935

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!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.glorb.com!usenet.stanford.edu!not-for-mail
From konsolebox <konsolebox@gmail.com>
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 22:22:52 +0800
Lines 23
Approved bug-bash@gnu.org
Message-ID <mailman.1010.1448893376.31583.bug-bash@gnu.org> (permalink)
References <70266BC6-C65A-4D95-B7C1-2F63F3C45DEF@qq.com> <20151130132909.GH27325@eeg.ccf.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace usenet.stanford.edu 1448893376 16928 208.118.235.17 (30 Nov 2015 14:22:56 GMT)
X-Complaints-To action@cs.stanford.edu
Cc ziyunfei <446240525@qq.com>, bug-bash <bug-bash@gnu.org>
To Greg Wooledge <wooledg@eeg.ccf.org>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=wxUFK/1gz/+fs9wYFVPGme8piItzIq9DlL0lE0vWdy8=; b=FCUiCyG7FCVAQzJQOvlatFhyeE3eyjGxqfc8PnO59hohTNZop7WmpZTbKBMMH3eKZR a+4B61Y9AWEbioSwOfyPx0qkPr4eGy5VDzSWdofzPo01k3ySf7tmgnpOltTROl3VDK5H PhVOYDSmBnPskh6wO81dF/S3Z87GqqIwyPcKJ9NOAou3eJW3bUNv62PkcRGHiTm4A1EI zmG3U9H9FzQua3JSmnn+oEunV4RnN2n2ppckXOTvP1TsRNPRcZzlQU8gb+qAmZpy1OkV r5MfxAcbeS/JAO5EbOm4WawOri4PZ9UkGMC4oe7014l7fIKkkQ1U73cHyh4BJbGukFcj Uy/A==
X-Received by 10.28.96.193 with SMTP id u184mr27186307wmb.64.1448893372533; Mon, 30 Nov 2015 06:22:52 -0800 (PST)
In-Reply-To <20151130132909.GH27325@eeg.ccf.org>
X-detected-operating-system by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value).
X-Received-From 2a00:1450:400c:c09::244
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:11935

Show key headers only | View raw


On Mon, Nov 30, 2015 at 9:29 PM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> 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.

That's also how I used to think about it, but I'm not sure when it has
been official.  No part of the documentation seems to tell that
`readonly` acts similar to `declare`, `typeset` and `local`.

Also a variable seems to be only made local when it is defined as an
array variable.

$ bash -c 'a=0; foo() { readonly a=(1); echo a=$a; }; foo; a=2; echo a=$a'
a=1
a=2
$ bash -c 'a=0; foo() { readonly a=1; echo a=$a; }; foo; a=2; echo a=$a'
a=1
bash: a: readonly variable

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 konsolebox <konsolebox@gmail.com> - 2015-11-30 22:22 +0800

csiph-web