Section: Associative Arrays

Create associative array

bash
bash
declare -A ports=([http]=80 [https]=443)
Explanation

Requires Bash 4 or newer.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Associative Arrays
Read associative array item
Read a value by key.
OpenIn sheetbashsame section
Loop through key/value pairs
Iterate through an associative array.
OpenIn sheetbashsame section
List associative array keys
Expand associative array keys.
OpenIn sheetbashsame section
Create indexed array
Create an indexed array.
OpenIn sheetbash1 tag match
Access array element
Read an array element by index.
OpenIn sheetbash1 tag match
Expand all array items
Expand all array items safely.
OpenIn sheetbash1 tag match