How to intialise arrays in bash script

An array is a variable containing multiple values may be of same type or of different type. There is no maximum limit to the size of an array, nor any requirement that member variables be indexed or assigned contiguously. Array index starts with zero.

We can initialise array in bash script using the following format.

array=( value1 value2 value3 )

Here we need to repalce the  value1, value2, value3 with the required ones.

If we need to display the contents of this array, use the following syntax.

array=( value1 value2 value3 )
for i in "${array[@]}"
echo $i

That's all.......


Leave a Reply