Link to home
Start Free TrialLog in
Avatar of mickt
micktFlag for Ireland

asked on

How best to correlate the variables in two arrays?

I want to correlate the variables in two arrays.  What's the simplest way of doing this?  I presume using index?  I'd also like to confirm that they both contain the same quantity of elements.

E.g. for below 10.10.12.16 correlates to 04 etc.

STORAGE=(10.10.12.16 10.10.12.20 10.10.12.22)
LVM=(04 07 08)

for i in ${STORAGE[@]}
do
echo $i >> file.txt
echo CORRESPONDING_LVM_VALUE >> file.txt
done
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mickt

ASKER

Cheers

And the 2nd part of question similar to the following:

if [ ${#STORAGE[@]} != ${#LVM[@]} ]
  then
    echo "STORAGE and LVM arrays do not contain the same quantity of elements.  Exiting."
    exit 1

fi
Avatar of mickt

ASKER

Sorry, missed your first section :).  cheers again.
Why grade B? Did you find my solution incomplete?
Avatar of mickt

ASKER

Not at all, very good solution.  Wasn't paying attention.  Can I change it?
Click "Request Attention" and ask the mods to reopen the question.