Holding Multiple Items
A standard Bash variable holds exactly one value. When you need to store a list — a set of server names, a collection of files to process, a sequence of commands to run — you need an array.
Bash supports indexed arrays: ordered lists where each element is accessed by a numeric index starting at zero.
Accessing elements requires curly braces — referencing an array element without them expands only the bare variable name and appends the index as literal text, not what a newcomer expects. Bash also supports negative indexing to count from the end of the array.
A handful of expansions cover most day-to-day array use: expanding to every element (always quoted, to keep elements containing spaces from being split into separate words by the shell), counting elements, listing every index, and appending a new element. Bash also supports slicing a subrange of elements by starting index and length.
Looping through an array with for element in "${ARRAY[@]}" is the standard pattern — and, as above, the quotes around the expansion are what keeps multi-word elements intact rather than silently splitting apart.
Building an array dynamically from the output of another command is a common ops pattern: piping a stream of lines into mapfile (also called readarray) captures each line as one array element, stripping the trailing newline from each. Feeding it via process substitution rather than a literal pipe means the array populated by mapfile is available in the current shell afterward, not lost inside a subshell the way a piped command's variables would be.