How are the "Associative Arrays" and "Indexed Arrays" declared in bash?

Solution Verified - Updated -

Issue

  • In this version of bash, the associative arrays are not working :
[root@rhel7u3-1 ~]# rpm -qa | grep bash 
bash-4.2.46-20.el7_2.x86_64 
bash-completion-2.1-6.el7.noarch 

[root@rhel7u3-1 ~]# declare -a B 
[root@rhel7u3-1 ~]# B[ddd]=aa 
[root@rhel7u3-1 ~]# B[AB]=cc
[root@rhel7u3-1 ~]# echo ${B["AB"]}
 cc
[root@rhel7u3-1 ~]# echo ${B["ddd"]}
 cc 
  • This is not correct for Bash Associative Arrays on my system with Red Hat Enterprise Linux 7.3
[root@test ~]# rpm -q bash 
bash-4.2.46-21.el7_3.x86_64

[root@test ~]# declare -a test 
[root@test ~]# test[a]=what
[root@test ~]# echo ${test[a]} 
what 
[root@test ~]# test[b]=that
[root@test ~]# echo ${test[a]} 
that 
[root@test ~]# echo ${test[b]} 
that

Environment

  • Red Hat Enterprise Linux 7
  • bash-4.2.46-20.el7_2.x86_64

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.