Bash Associative Arrays

Written By
MF
Mitch Frazier
Apr 30, 2010

“The bash man page has long had the following bug listed: “It’s
too big and too slow” (at the very bottom of the man page). If you
agree with that, then you probably won’t want to read about the
“new” associative arrays that were added in version 4.0 of bash. On
the other hand, if you’ve ever used any modern Office Suite and
seen code-bloat at its finest and just think the bash folks are
exaggerating a bit, then read on.

“There’s nothing too surprising about associative arrays in
bash, they are as you probably expect:

declare -A aa
aa[hello]=world
aa[ab]=cd

“The -A option declares aa to be an associative array.
Assignments are then made by putting the “key” inside the square
brackets rather than an array index. You can also assign multiple
items at once:”

Complete
Story

MF

Mitch Frazier

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.