[Bash] Read the first element of an indexed array

Created on November 30, 2026

Use index 0 to read the first element of a Bash array initialized with consecutive indexes.

items=(apple banana cherry)
echo "${items[0]}"
apple

Quote the expansion so a value containing spaces is still one argument.

Omit the index

Using the array name without an index also reads element 0.

items=(apple banana cherry)
echo "${items}"
apple

Writing the index explicitly can make the intent easier to see.

Reference

Bash Shell command