in accordance to its genetic arrange of chemical reactions.
I mean, the bacteria do not know they are surviving. At least it is just my guess.
About how a self prevails I will adventure a hypothesis...