shell array

A variable that holds a numbered list of separate values, written in bash as names=(one "two words" three).

In more detail

Elements are numbered from 0 and a negative index counts from the end. "${names[@]}" expands to one word per element, keeping spaces inside elements intact, which makes arrays the safe way to build lists of file names or command arguments. Arrays are a bash feature, not part of POSIX sh.

Examples

files=('two words.txt' poem.txt)
for f in "${files[@]}"; do echo "$f"; done

Related terms

Taught in

References