associative array
A bash 4 array indexed by strings instead of numbers, declared with declare -A.
In more detail
It maps keys to values, like a small lookup table, as in owner[report]=ada. It must be declared before use and does not exist in bash 3.2, which is why a script that uses one should check BASH_VERSINFO first. The order of keys when you list them is not guaranteed.
Example
declare -A owner; owner[report]=ada; echo "${owner[report]}"Related terms
- shell array — A variable that holds a numbered list of separate values, written in bash as names=(one "two words" three).
- declare — The bash builtin that creates variables with attributes: -i integer, -r read-only, -a array, -A associative array, -n name reference, and -p to print.
- BASH_VERSINFO — Built-in bash variables giving the running version: BASH_VERSION as a string and BASH_VERSINFO as an array of its parts.
Taught in
- Which Shell Am I In, And Getting Bash Five — Bash Scripting & Command Line Automation
- eval, And What To Use Instead — Bash Scripting & Command Line Automation