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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s