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
  • 83
  • 1
  • 1
  • 4
  • haven't got the time, but use `comm -12 <(printf "%s\n" "${arr1[@]}") <(printf "%s\n" "${arr2[@]}")` – KamilCuk Feb 21 '19 at 07:54

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,419
  • 1
  • 15
  • 27