Matching part of a string that is in an array

I am trying to do a comparison to see if these two string arrays match.

I have tried assigning the array variable to another variable to get it to work but i can't figure it out. Here is what I have.

#example of items that could be in the array
#string[1]="TEST"
#string[2]="56486TR126843574TRTEST"

y=${#sting1[@]}
z=${#sting2[@]}

for ((j=0; j<$y; j++))
do
var1=${string1[$j]}
     for ((k=0; k<$z; k++))
     do
     var2=${string2[$k]}
     if [ "$var1" = "${*%var2}" ]
     then
     echo "works"
     else
     echo "doesn't work
     fi
     done
done

I want to check and see if string2 has string 1 at the end of it. The length of the numbers in string2 changes with each variable. I would like the if statement to look something like this

if [ "${string1[$j]}" = "${*%sting2[$k]} ]
then
echo "works"
else
echo "doesn't work"
fi

Any help would be appreciated.

This worked for me:string1="TEST"string2="56486TR126843574TRTEST1";echo " " | awk -v s1=$string1 -v s2=$string2 's1==substr(s2,length(s2)+1-length(s1)) { print "true" }'

Thanks for the quick reply.
how would i go about making that so that it would also work if I wanted to know if they were not equal?

echo " " | awk -v s1=$string1 -v s2=$string2 's1==substr(s2,length(s2)+1-length(s1)) ? $0="true" : $0="false" { print $0 }'

1 Like