Shell Script: Usage of Arrays

#!/bin/bash

if [ “$#” -ne “9” ]
then
echo “Pass 9 CMD LINE arguments …”
exit
fi

arg[1]=$1
arg[2]=$2
arg[3]=$3
arg[4]=$4
arg[5]=$5
arg[6]=$6
arg[7]=$7
arg[8]=$8
arg[9]=$9

for i in {1..9}
do
echo “${arg[i]}”
done

 

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: