Finding an element

Arrays and collections / Sets

#bash has no set: the keys of an associative array make one
declare -A chars=([A]=1 [B]=1 [C]=1 [D]=1)

#-v checks that the key is there (bash 4.3 and newer)
[[ -v chars[A] ]] && containA=true || containA=false
#containA is true
[[ -v chars[E] ]] && containE=true || containE=false
#containE is false

#every element of chars2 is in chars: the loop stops
#at the first one that is missing
declare -A chars2=([A]=1 [B]=1)
containAll=true
for char in "${!chars2[@]}"; do
    if [[ ! -v chars[$char] ]]; then
        containAll=false
        break
    fi
done
#containAll is true

echo "containA is $containA"
echo "containE is $containE"
echo "containAll is $containAll"