Comparing multiple variables

Hi!

I've come up with a ksh-script that produces one or more lists of hosts.
At the and of the script, I would like to print only those hosts that exists in all the lists.

Ex.
HOSTS[1]="host1 host2 host3 host11"
HOSTS[2]="host1 host2 host4"
HOSTS[3]="host2 host11"
HOSTS[4]="host2 host5 host6 host7 host8"

This should generate a print-out of "host2" only.
How can I do this in a effective manner?

My current solution is not exact, so it would render a output of "host1 host2" as "host1" is part of string "host11".
($run contains the number of host-rows that are produced earlier)

for candidate in ${HOSTS[1]};do
HIT=true
for (( i=1;i<=$run;i++ ));do
if [ $(($i+1)) -le $run ];then
if ! [[ ${HOSTS[$i+1]} = *"$candidate"* ]];then
HIT=false
fi
fi
done
if [ x${HIT} = xtrue ];then
FINAL="$FINAL $candidate "
fi
done

Any ideas how to solve this?

//Br Bugenhagen

Hello,

I would go this way in ksh:

#!/usr/bin/ksh
HOSTS[1]="host1 host2 host3 host11"
HOSTS[2]="host1 host2 host4"
HOSTS[3]="host2 host11"
HOSTS[4]="host2 host5 host6 host7 host8"

# declare array count as associative
typeset -A count

# loop through HOSTS array
for index in "${!HOSTS[@]}"; do

	# for each index, loop through value and increment assoc. array
	for host in ${HOSTS[$index]}; do

                # increment counter array
		((count[$host]++))

		# print host name if counter = number of indexes in HOSTS array
		if [[ ${count[$host]} = ${#HOSTS[*]} ]]; then
			print $host
		fi
	done
done

exit 0