Give effects to entities if they are standing on a specific block

I've been trying to give mobs effects if they stand on a specific block (for example, if a sheep stands on grass, it gets regeneration) using this command:

/execute @e[type=Sheep] ~ ~ ~ detect ~ ~ ~ grass 0 effect @e[type=Sheep] regeneration 1 0

However, it targets all sheep, even if only one fulfills the criteria.


Solution 1:

Use c=1 so that the sheep successfully detecting the grass will only target itself:

/execute @e[type=Sheep] ~ ~ ~ detect ~ ~-1 ~ grass 0 effect @e[type=Sheep,c=1] regeneration 1 0