I have seen plenty of remarks on how to do this right, but somehow it does not work for me, and I am not sure why, some help would be appreciated.
Example Code:
#!/bin/bash
echo -en "\ec"
echo "."
#Dig MX Record
DIG="$(which dig --skip-alias)"
CurrentDomain="example.com"
echo -n "${CurrentDomain} MX "
CurrentMX="$(${DIG} ${CurrentDomain} MX +short)"
readarray -t ArrMX <<< "$CurrentMX";
if [[ -n ${ArrMX[@]} ]]
then
printf '%s\n' "${ArrMX[@]}"
else
echo "No Entry"
fi
As you can see this is only part of a Program that loops over a list, most of the values work, but when dig returns nothing cause it has no MX entry, I get MX: unbound variable yet I do the -z test...
Any suggestions?