0

arr1 contains elements "a" "b" "c"

arr2 contains element "b"

if elements of arr2 exist in arr1, then do....

How would I write this?

something along the lines of

for x in arr1
do
    if [ ${arr1[x]} == ${arr2[*]} ]
    then ...
    fi
done

?

John Dingus
  • 53
  • 1
  • 4

1 Answers1

0

Checking values in arr2 present in arr1 :

arr1=("a" "b" "c")
arr2=("c" "d" "e")

for i in "${arr2[@]}" 
do 
  for j in "${arr1[@]}" 
  do 
  [[ "$i" == "$j" ]] && echo "$i" 
  done 
done

--> prints : c

nullPointer
  • 4,188
  • 1
  • 14
  • 27