# Associative Arrays: Lists with Names

An associative array finds each value by a name instead of a number: declare -A total makes one, total\[chill\]=15 stores a value under a name, "${!total\[@\]}" lists the names, and adding to total\[$mood\] inside a loop keeps a total for every category; it needs bash 4 or newer, which on a Mac means bash 5 from Homebrew.

![Cheat sheet for the lesson Associative Arrays: Lists with Names: An associative array finds each value by a name instead of a number: declare -A total makes one, total\[chill\]=15 stores a value under a name, "${!total\[@\]}" lists the names, and adding to total\[$mood\] inside a loop keeps a total for…](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/4074b5b63b974969bdf750399607c5d0.webp)

- Category: Bash
- Level: Freelancer
- Tags: associative-array, declare, homebrew, key-value-pair, linux, unix
- Updated: November 10, 2026

Source: https://www.ask-codey.com/cheat-sheets/bash-associative-arrays-cheat-sheet
