Similar to this >> In bash, how can I check if a string begins with some value?, but not duplicated.
I have two arrays, and for each string inside the first one, I wanna check whether the strings in the second one start with the string from the first one or not.
array1=("test1","test2","test3");
array2=("test1 etc","test1 nanana","test2 zzz","test3 abracadabra");
for i in "${!array1[@]}"; do
for j in "${!array2[@]}"; do
if [[ "${array1[i]}" == "${array2[j]}*" ]]; then
echo "array1[$i] and arry2[$j] initial matches!";
fi;
done;
done
I tried many conditions inside if, such as:
if [[ "${array1[i]}" == "${array2[j]*}" ]]
if [[ "${array1[i]}" == "${array2[j]}*" ]]
if [[ "${array1[i]}" = "${array2[j]*}" ]]
if [[ "${array1[i]}" = "${array2[j]}*" ]]
Also without quotes, braces, and so on, all with no success.