Shell Script: Usage of Arrays

#!/usr/local/bin/bash
area[11]=23
area[13]=37
area[51]=test

echo -n “area[11] = ”
echo ${area[11]} # {curly brackets} needed

echo -n “area[13] = ”
echo ${area[13]}

# Contents of uninitialized array variable print blank.
echo -n “area[43] = ”
echo ${area[43]}

#sum of two array variables assigned to third
area[5]=`expr ${area[11]} + ${area[13]}`
echo “area[5] = area[11] + area[13]”
echo -n “area[5] = ”
echo ${area[5]}
****

Thanks,
Ravi

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

%d bloggers like this: