Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # the two original arrays
- bash-4.1$ array1=(a b c d)
- bash-4.1$ array2=(a h c d l k)
- # lookup array
- bash-4.1$ declare -A array2rev
- bash-4.1$ for i in "${!array2[@]}"; do array2rev["${array2[i]}"]="$i"; done
- # checking elements in the lookup array
- bash-4.1$ for i in "${array1[@]}"; do echo "element $i of first array is $([[ "${array2rev[$i]}" ]] || echo 'NOT ')present in the second array"; done
- element a of first array is present in the second array
- element b of first array is NOT present in the second array
- element c of first array is present in the second array
- element d of first array is present in the second array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement