Bash provides one-dimensional indexed and associative array variables: any variable may be used as an indexed array, declare -a name declares one explicitly, and declare -A name creates an associative array. There is no maximum limit on size and no requirement that members be indexed or assigned contiguously. Indexed arrays are zero-based, and a negative subscript counts back from one greater than the maximum index, so -1 references the last element. Assigning name[subscript]=value automatically creates an indexed array; compound assignment name=(value1 value2 ...) assigns many elements at once, and when no subscript is supplied each element takes the last assigned index plus one. Reference elements as ${name[subscript]} — the braces are required to avoid conflicts with filename expansion. A subscript of @ or * expands to all members; double-quoted, ${name[@]} expands each element to a separate word while ${name[*]} joins members into a single word separated by the first character of IFS. ${#name[@]} is the element count and ${!name[@]} expands to the assigned indices. unset name[subscript] removes one element; unset name removes the entire array. Scope: Bash. Reviewed October 4, 2026.
Indexed and associative arrays
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- www.gnu.org
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.