Array is another important component of programming, Now we will see how to use Array in bash or shell script .

In Bash, there are two types of arrays. There are the associative arrays and integer-indexed arrays. Elements in arrays are frequently referred to by their index number, which is the position in which they reside in the array. These index numbers are always integer numbers which start at 0.Associative array are a bit newer, having arrived with the version of Bash 4.0.

Integer-Indexed Array

array=( element element element element )

Associative arrays

$ declare -a array_name

Let's Execute

$ ./array.sh  

Output

Integer-Indexed Array
A
B
C
D
-------------------
12 3 4
All elements 
12
3
4
-------------------
Sum of all array index: 150

You can check these codes for better understanding.