Indexed arrays and associative arrays

Bash provides a feature to declare a list (or array) of variables in a one-dimensional array that can be an indexed array or associative array. The size of an array can be 0 or more.

Indexed arrays

An indexed array contains variables that may or may not have been initialized continuously. Indices of an indexed array start from 0. This means that the first element of an array will start at an index 0.

Array declaration and value assignment

An indexed array can be declared by just initializing any index as follows:

array_name[index]=value

Here, an index can be any positive integer or an expression must be evaluated to a positive integer.

Another way of declaring is by using the declare shell built in as follows: ...

Get Linux Shell Scripting Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.