Java 26.2
/execute if entity
@e[type=minecraft:zombie,limit=1]/execute if entity
Wrap a command behind an entity selector condition.
/execute if entity @e[type=zombie,limit=1] run say matched
Selector condition
Most broken commands are broken selectors, not broken syntax. Build the /execute if entity condition here with explicit filters, and test it with a harmless command before wiring it to something that damages, kills or teleports.
/execute if entity <selector> run <command> executes the trailing command only when the selector matches at least one entity. Build the selector filters here and test with a harmless command before wiring it to something destructive.
Most broken commands are broken selectors, not broken syntax -- a wrong type, tag, or distance filter. Narrow the selector step by step, and remember distance and coordinates are relative to the execution position, not the command block.
if entity runs when the selector matches; unless entity runs when it does not. Swapping the two is a common logic bug when building conditional command chains.
Java 26.2
@e[type=minecraft:zombie,limit=1]Wrap a command behind an entity selector condition.
/execute if entity @e[type=zombie,limit=1] run say matched