Bash array manipulation

seeking assistance on comparing two arrays using bash:

array1=(disk1, disk2, disk3, disk5, disk7, vol1, vol2, vol3, vol4, vol5)
array2=(disk2, disk5 vol2, vol4 )

1) if two arrays have same elements; EXIT
else populate array3 & array4 with elements that are different between array1 & array2 as:

array3=(vol1, vol3, vol5)
array4=(disk1, disk3, disk7)

thanks in advance

Try this and assign to arrays 3 & 4 accordingly:

$ grep -vf <(echo "${array2
[*]}"|tr -s ', ' '\n') <(echo "${array1
[*]}"|tr -s ', ' '\n')
disk1
disk3
disk7
vol1
vol3
vol5

looks like there is no "f" flag that goes along with grep (Solaris).Without the f flag, dont think i got what i wanted:

#!/usr/bin/bash
array1=( `cat /tmp/array1 `)
array2=( `cat /tmp/array2 `)
echo "Elements in array1: ${array1[@]}"
echo "Elements in array2: ${array2[@]}"
grep -v <(echo "${array2[*]}"|tr -s ', ' '\n') <(echo "${array1[*]}"|tr -s ', ' '\n')
./test-array.sh
Elements in array1: disk1 disk2 disk3 disk5 disk7 vol1 vol2 vol3 vol4 vol5
Elements in array2: disk2 disk5 vol2 vol4
disk1 disk2 disk3 disk5 disk7 vol1 vol2 vol3 vol4 vol5

[/CODE]
so the output is exactly array1 not the non-commom elements between the two.
I need: disk1 disk3 disk7 vol1 vol3 vol5
also i need (disk1 disk3 disk7) & (vol1 vol3 vol5) as two separate arrays from the output.

From the man pages in this forum:

Watch out - there's two grep s in solaris!