TECHIES WORLD

For Techs.... Techniques.... Technologies....

CpanelLinux

How to append values to array in bash

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 initialize an empty array in bash script using the following format.

array=()

For appending elements to this array we need to use the below formats.

array+=('element1')

array+=('element2')

Where element1 and element2 are the values need to append to this array. We can follow this procedure to add any number of elements to the array.

 

Leave a Reply