You are currently viewing Shell Scripting – Array

Shell Scripting – Array

Shell Scripting – Array

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed IO redirection in shell.

In this blog post, we will discuss array in shell. Like any other programming language, bash also supports the use of an array. An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index tuple by a mathematical formula. The simplest type of data structure is a linear array, also called a one-dimensional array. Bash only supports a one-dimensional array.

Shell Scripting – Array:

Array declaration and initialization:

In bash, an array can be declared using () or using an array index number. An array can hold all the supported data types available in bash and you can also mix different data types in a single array.

Array Index:

Array index starts with zero representing the first element of the array and is incremented by one for each subsequent array element. You can get a specific array element using its associated index value.

Array Operations:

You can add, substitute, remove or concatenate array elements.

Hope you have enjoyed this article. In the next blog post, we will discuss functions.


Leave a Reply