Arrays in ksh

# how to create a array and assign a list of values
set -A fruit apples pears oranges banana
# print the first element in the array
print $fruit[0]
# set a new value to element 1
$fruit[1]=watermelon

# how to get number of elements in the array
$ x[1]=5 x[2]=3 x[3]=6 x[11]=55
$ print ${#x[*]}
4

# Looping through an array
$ for place in ${x[*]}
do
print $place
done
5
3
6
55

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