/execute
This article is about the
/execute command before Java Edition 1.13 and Bedrock Edition 1.19.50. For the main command in current versions, see Commands/execute.This page describes content that has been removed from the game.
This feature was present in earlier versions of Minecraft, but has since been removed.
/execute| Permission level required |
|
|---|---|
| Restrictions |
Cheat only |
{
"title": "<code>/execute</code>",
"rows": [
{
"field": "\n* 2 <sup class=\"noprint nowrap Inline-Template \" title=\"\">[<i><span title=\"This statement only applies to Java Edition\">(link to Java Edition article, displayed as JE) only</span></i>]</sup>\n* 1 <sup class=\"noprint nowrap Inline-Template \" title=\"\">[<i><span title=\"This statement only applies to Bedrock Edition\">(link to Bedrock Edition article, displayed as BE) only</span></i>]</sup>",
"label": "(link to Permission level article, displayed as Permission level<br>required)"
},
{
"field": "(link to Options article, displayed as Cheat) only<sup class=\"noprint nowrap Inline-Template \" title=\"\">[<i><span title=\"This statement only applies to Bedrock Edition\">(link to Bedrock Edition article, displayed as BE) only</span></i>]</sup>",
"label": "(link to Commands#Restrictions article, displayed as Restrictions)"
}
],
"invimages": [],
"images": []
}
Executes a command on behalf of one or more other entities, with originating permissions, optionally on condition that a single-block /testforblock-style check passes.
Syntax
execute <entity> <x> <y> <z> <command …>
- An alternate syntax allows the command to be executed only if a specific block is detected:
execute <entity> <x> <y> <z> detect <x2> <y2> <z2> <block> <dataValue|state> <command …>
execute <origin: target> <position: x y z> <command: command>
- An alternate syntax allows the command to be executed only if a specific block is detected:
execute <origin: target> <position: x y z> detect <detectPos: x y z> <block: Block> <data: int> <command: command>
Arguments
JE: entity
BE: origin: target: CommandSelector<Actor>
- Specifies the target to be the command's executor. Must be a player name or target selector. If more than one entity is selected, the command is run once as each of them.
JE: x y z
BE: position: x y z: CommandPositionFloat
- Specifies the position from which to run the command. Coordinates specified with tilde and caret notation are relative to the target, not to the position of the command's execution.
JE: command
BE: command: command: unique_ptr<Command>
- Specifies the command to be run. Must be a valid command.
JE: x2 y2 z2
BE: detectPos: x y z: CommandPosition
- Specifies the position of the block to check. May use tilde and caret notation to specify distances relative to
position: x y z.
- Specifies the position of the block to check. May use tilde and caret notation to specify distances relative to
JE: block
BE: block: Block: enum
- Specifies the block ID that the block at x2 y2 z2 or
detectPosmust match for the command to run. Must be a valid block ID.
- Specifies the block ID that the block at x2 y2 z2 or
JE: dataValue
BE: data: int: int
- Must be a valid block data for that type of block or
-1to match any block data.
- Must be a valid block data for that type of block or
JE: state
- Must be a valid block state for that type of block or
*to match any block state.
- Must be a valid block state for that type of block or
Result
- Fails if arguments are not specified correctly, if entity or
origin: targetfails to resolve to one or more valid entities (named players must be online), if the checked block is not of the correct block id, data or state, or if the specified command fails.
- On success, executes the specified command as if executed by the specified target(s), done with operator-level permission at the specified coordinate.
Examples
- To summon lightning bolts at the positions of every zombie:
execute @e[type=zombie] ~ ~ ~ summon lightning_bolt
- To summon lightning bolts at the positions of every zombie standing on any type of sand:
execute @e[type=zombie] ~ ~ ~ detect ~ ~-1 ~ sand -1 summon lightning_bolt
- To summon 10 creepers at the nearest player's position (works as long as there are at least 10 entities in the loaded world):
execute @e[c=10] ~ ~ ~ execute @p ~ ~ ~ summon creeper ~ ~ ~
- To summon an ender dragon at the position of another player:
execute @a[name=name_of_player] ~ ~ ~ summon ender_dragon
History
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.8 | 14w07a | Added /execute. | |||||
| 14w08a | Commands run using /execute now pass their success value back to the command block running them. | ||||||
| 1.11 | 16w32a | Added block state support to /execute. | |||||
| 1.13 | 17w45a | Reworked /execute. See Commands/execute for new syntax. | |||||
| Pocket Edition Alpha | |||||||
| v0.16.0 | build 1 | Added /execute.
| |||||
Functionality almost is equivalent to Java Edition 1.10 usage, except the entity target is optional in /execute. | |||||||
| Bedrock Edition | |||||||
| 1.19.10 Experiment | Preview 1.19.10.20 | Added new /execute syntax to closer resemble that of Java Edition. | |||||
| 1.19.50 | Preview 1.19.50.23 | The new /execute syntax is no longer behind the "Upcoming Creator Features" experimental toggle. | |||||
See also
/testforblock— tests for a certain block at a specified position (including specific data tags)