Check if array is empty in Bash
Supposing your array is $errors
, just check to see if the count of elements is zero.
if [ ${#errors[@]} -eq 0 ]; then
echo "No errors, hooray"
else
echo "Oops, something went wrong..."
fi
I generally use arithmetic expansion in this case:
if (( ${#a[@]} )); then
echo not empty
fi