bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to initialize a read-only, global, associative array in Bash?


From: Roman Rakus
Subject: Re: How to initialize a read-only, global, associative array in Bash?
Date: Tue, 27 Nov 2012 14:34:09 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1

On 11/26/2012 10:45 PM, Tim Friske wrote:
Hi folks,
Hi

I execute the following code in Bash version "GNU bash, Version
4.2.39(1)-release (x86_64-redhat-linux-gnu)":

function foobar {
   declare -rgA FOOBAR=([foo]=bar)
}
foobar
declare -p FOOBAR
# Output: declare -Ar FOOBAR='()'
I think there should be also -g but it is not

Why doesn't Bash initialize FOOBAR with ([foo]=bar) according to
declare -p? The same declaration works outside of a function, e.g.

declare -rgA FOOBAR=([foo]=bar)
declare -p FOOBAR
# Output: declare -Ar FOOBAR='([foo]="bar" )'

Similarly the following code but without FOOBAR being read-only works:

function foobar {
   declare -gA FOOBAR
   FOOBAR=([foo]=bar)
}
foobar
declare -p FOOBAR
# Output: declare -A FOOBAR='([foo]="bar" )'

Is this a bug or feature?

Cheers,
Tim

BTW: I couldn't find a "bashbug" RPM package in the Fedora 17
repositories; that's why I wrote this formless mail. Sorry for that.
/usr/bin/bashbug-64
I will try to add symlink or something. Thanks
--
`~~~~°<
C92A E44E CC19 58E2 FA35 4048 2217 3C6E 0338 83FC





reply via email to

[Prev in Thread] Current Thread [Next in Thread]