[Bash] Create an associative array

Created on November 30, 2026

Use declare -A to create an associative array. This example sets values for the name and age keys and accesses them by key.

declare -A user

user[name]="Taro"
user[age]="25"

echo "${user[name]}"
echo "${user[age]}"

Output

Taro
25
Bash