Bash: Array difference
Loop approach
A=("alpha" "beta" "gamma" "delta" "epsilon")
B=("alpha" "beta" "gamma" "delta")
NOT_IN_A=()
for A_ITEM in "${A[@]}"; do
for B_ITEM in "${B[@]}"; do
[[ $A_ITEM == "$B_ITEM" ]] && continue 2
done
NOT_IN_A+=( "$A_ITEM" )
done
echo "${NOT_IN_A[@]}" # epsilon
With comm
command
A=("alpha" "beta" "gamma" "delta" "epsilon")
B=("alpha" "beta" "gamma" "delta")
NOT_IN_A=($(comm -23 <( printf '%s\n' "${A[@]}" | LC_ALL=C sort ) <( printf '%s\n' "${B[@]}" | LC_ALL=C sort )))
echo "${NOT_IN_A[@]}" # epsilon