[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
declare -gA <Name> does not create globally accessible associative array
From: |
Florian Mayer |
Subject: |
declare -gA <Name> does not create globally accessible associative array |
Date: |
Sun, 19 Oct 2014 22:59:28 +0000 (GMT) |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib
-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
-Wformat-security -Werror=format-security -Wall
uname output: Linux klingon 3.2.0-70-generic #105-Ubuntu SMP Wed Sep 24
19:49:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.2
Patch Level: 25
Release Status: release
Description:
The problem is, that declare -gA <NAME> does not create
a globally accessible object if run from a sourced file inside
a function.
(see http://lists.gnu.org/archive/html/bug-bash/2014-05/msg00039.html)
Repeat-By:
=script init.sh=
#!/bin/bash
. foo.sh
=script foo.sh=
#!/bin/bash
init(){
. bar.sh
. func.sh
}
init
func_func
=script bar.sh=
#!/bin/bash
# sould declare associative array globally
declare -gA FOO(
[FOFU]="42"
)
=script func.sh=
#!/bin/bash
func_func(){
# Won't return "42"
echo ${FOO[FOFU]}
return 0
}
Fix:
Add a declare -gA to the beginning of foo.sh
solves the problem.
- declare -gA <Name> does not create globally accessible associative array,
Florian Mayer <=