Indexed arrays keep an ordered list of values. A numeric index selects one value without rewriting the rest of the script.

Program

Play the script to choose the index and see which array element is selected.

indexed_array_pick.sh
#!/usr/bin/env bash

names=("api" "web" "db")
index=
selected="${names[$index]}"
echo "$index:$selected"
#!/usr/bin/env bash

names=("api" "web" "db")
index=
selected="${names[$index]}"
echo "$index:$selected"
indexed array An indexed array stores values by numeric position.
array element `${names[$index]}` reads one element from the array.
zero-based index The first array position is index `0`; index `1` is the second value.