Minecraft wiki entry for execute, associated text: Sets the command's executor to target entity, without changing execution position, rotation, dimension, or anchor
Syntax
as <targets> -> execute
Arguments
<targets>: entity
Target entity/entities to become the new executor.
Must be a player name, a target selector or a UUID.
Result
Executor is updated to target entity (which changes the meaning of @s).
Unparseable if the argument is not specified correctly.
Terminates if <targets> fails to resolve to one or more valid entities (named players must be online).
When multiple entities are selected, next sub-command is executed once by each executor.
Example
Get data of all sheep: execute as @e[type=sheep] run data get entity @s‌[Java Edition only]
Make all villagers in loaded chunks invincible: execute as @e[type=villager] run data merge entity @s {Invulnerable:1}‌[Java Edition only]