I created a bash script that gets a file formats it, sends an email to the user(s), however, for whatever reason, it will send an email per line with all of the lines in it, so essentially the user will get 10 duplicate emails with the same 10 results. I've modified the script to put the results of each user into a file with the user's email address, but I'm not sure how to limit the script to send only one email on however many lines there is for each user. Please see what I have, I'd appreciate any suggestions.
Code:
printf "${EMAIL%%@*},\n\n$MESSAGE\n\n$DETAIL" | mailx -r admin@admin.com -s "test" "$EMAIL"
DETAIL=''
done
Is there any way I can have some sort of function or something that will only allow to send one email? I'm a bit stumped as to how to fix it.