I write this script:
for ip in ${ARRAY[*]}; do
for e in ${ARRAY[*]}; do
echo $e
done | grep -c "$ip" | if [[ "$(cat)" -lt "10" && $sent != *"$ip"* ]]; then
sent=$sent$ip
sed -n "/$ip/p" $1 | mail -s "subject" "mail@mail.mail"
fi
done
I want to get each element from ARRAY
and count how many time This item is in ARRAY
. If this count is less than 10 and this element is the first time it is counted (to avoid count an element twice), an email is sent.
However, sent
variable does not save the strings concatenate. If I made an echo $ sent
just after its assignment, sent returns the expected result.
If I make echo $ sent
just after fi
, the variable is already empty. Obviously, by this way, two elements are tacking in account and two mails are sent instead of just one.
What am I doing wrong?