Creating Array in bash

Just a copy paste from this link

to create an array using bash script:

#!/bin/bash
#Create array of string
ARRAY=( 'one' 'two' 'three' 'four' )
# get number of elements in the array
ELEMENTS=${#ARRAY[@]}
# echo each element in array
# for loop
for (( i=0 ; i < $ELEMENTS ; i++)); do
echo ${ARRAY[${i}]}
done

Leave a comment