O'Reilly logo

Linux Shell Scripting Essentials by Sinny Kumari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required