Skip to content
Shell & TerminalNews Published Updated 3 min readViews unavailable

Bash 4.0 Ships With Associative Arrays and Coprocesses

Announced by maintainer Chet Ramey on February 20, 2009, Bash 4.0 added key-value associative arrays and other features scripters had requested for years.

On February 20, 2009, Chet Ramey — Bash’s maintainer since the early 1990s — announced the release of Bash 4.0, adding several substantial scripting features requested by users for years.

The headline feature: associative arrays

Bash 4.0, released after several years of steady Bash 3.x incremental point updates spanning much of the mid-2000s, introduced genuine associative arrays — arrays indexed by arbitrary strings rather than only sequential integers, conceptually similar to a dictionary or hash map in other languages. Before this, Bash scripters needing key-value data structures had to work around the limitation with less direct techniques; associative arrays gave scripts a genuinely native way to express that data shape.

Other notable additions in the same release

Bash 4.0 also added case-modifying word expansions (converting a variable’s value to upper or lower case directly within expansion syntax), support for the ** recursive glob pattern (matching directories recursively when globstar is enabled), and the coproc keyword, which lets a script run an asynchronous coprocess connected to the calling shell via two pipes for bidirectional communication.

Why these specific additions mattered for real-world scripting

Associative arrays in particular closed a genuine capability gap for scripts needing structured data — configuration mappings, lookup tables — without reaching for an external tool like awk just to get key-value semantics. The recursive globbing addition similarly simplified a common pattern (finding files recursively) that previously required find in most cases.

How this fits into Bash’s ongoing, decades-long development

Bash 4.0’s release, twenty years after Brian Fox’s original 1989 release, reflects the shell’s continued, incremental evolution under Ramey’s long-running maintainership — new major and minor versions have continued shipping since, but Bash 4.0 remains a commonly cited milestone specifically because associative arrays addressed such a widely felt scripting limitation.

The other genuinely useful addition: mapfile

Bash 4.0 also introduced the mapfile builtin (aliased as readarray), which reads lines of input directly into an indexed array without a manual loop or command substitution — mapfile -t lines < file.txt populates the lines array with the file’s contents in one step, trailing newlines stripped by the -t flag. Because it’s implemented as a genuine builtin rather than running through a subshell the way a while read loop typically does, it’s also meaningfully faster for reading large files into memory, which made it a quiet but genuinely practical addition alongside the more headline-grabbing associative arrays.

Recursive globbing in more depth

The ** pattern this release enabled (via shopt -s globstar) matches files and directories recursively through an arbitrary depth of subdirectories, something earlier Bash versions simply had no built-in syntax for at all — ls **/*.txt with globstar enabled finds every .txt file anywhere under the current directory tree, where earlier Bash required piping through find to get equivalent behavior. Because this is opt-in via shopt rather than default behavior, a script relying on ** recursion needs to explicitly enable globstar itself rather than assuming it’s already active, particularly when the script might run on an older Bash version or one with different default shell options configured. A script assuming ** recursion works without confirming globstar is actually enabled is a specific, common, and easy-to-miss source of “works on my machine” bugs in shared shell scripts, since the failure mode is silent — the pattern simply doesn’t match recursively, without any error message ever explaining why the expected files were never found at all during that particular script run.

Related:

Sources:

Comments