Commands/execute

is a versatile command that executes other commands in a variety of scenarios:

Java Edition

 * Syntax

There are twelve instructions for the  command, and each has its own special syntax, so describing syntax takes a largely branching tree.


 * {| class="collapsible collapsed collapse-button-none" data-description="Command Syntax Tree-Diagram"

! style="text-align:left" | Command Syntax Tree-Diagram
 * }


 * Full syntax tree:
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.
 * ... where  represents the start of another execution instruction. A number of instructions can be strung end-to-end, where   is the only instruction that can terminate the command. Including the   or   instructions allows this terminator to be left out.


 * Details


 * There are 11 chainable instructions&mdash;9 instructions that modify command behaviour and 2 conditional instructions&mdash;and a final  instruction for carrying out some following command. A number of instructions can be chained together, but   finalises the command.  The simplest usage for this command is:.


 * Alternatively, using the conditional instructions  or   without   is still valid syntax, in which case the result of the test is returned:


 * The conditional instructions  and   can prevent a command from running at all. All specified conditions must be met for the test to pass and the command to run.


 * The 11 chainable instructions are:


 * Align the current position to the block grid, rounding down (towards negative infinity).
 * &mdash;Any non-repeating combination of the characters 'x', 'y', and 'z'. (For example,,  ,  , or  .)
 * Example: Given the position (-1.8, +2.3, +5.9), the command carried out by "/execute align xz -> execute" instead uses (-2.0, +2.3, +5.0) as the "current position."
 * Example: Given (+2.4, -1.1, +3.8), using "/execute align yxz -> execute" carries the command out with (2, -2, 3) as the "current position."
 * Use either feet or eye height for "^ ^ ^" or "~ ~ ~" coordinates and facing commands.
 * Use the targeted entity/entities, but don't change "current position." If an entity doesn't have an eye anchor point, the command anchors to the feet of the previous executor (not the specified entity).
 * Use the position, rotation, and dimension of the target, but don't change "target entity."
 * Use an execution position that faces either the given position or the targeted entity's eyes or feet.
 * Execute as though the executor is in the given dimension.
 * &mdash;Can be "overworld", "the_nether", "the_end", or any dimension not in the Minecraft namespace.
 * Use either the given coordinates or the targeted entity's coordinates for the "current position."
 * Execute as though the executor is rotated either in the given direction or the same the targeted entity is facing.
 * Store the result or success of a command somewhere. This instruction replaced the "/stats" command.
 * &mdash;Return the result of the command. (This replaces the old stats AffectedBlocks, AffectedEntities, AffectedItems, QueryResult.)
 * &mdash;Return how many times the command was successful. This is usually  or , but if the command split up (as perhaps with "/execute as @a -> execute") then success can be a number higher than  . (This replaces the old stat SuccessCount.)
 * If a command fails, "success" and "result" both return 0. The return value is stored when the full command has finished executing.
 * Saves the return value in NBT data at the given block position.
 * &mdash;Name of the data tag to save return value in. See  below for more details.
 * Saves the return value in either the current value or the maximum value of the given bossbar
 * &mdash;ID of the bossbar to store return value in.
 * &mdash;Specifies that the bossbar's "value" is to be overwritten with the execution's return value
 * &mdash;Specifies that the bossbar's "max" is to be overwritten with the execution's return value
 * Use the data tag  from one targeted entity to save the return value. Store as a byte, short, int, long, float, or double.
 * Like the "/data" command, "/execute store " cannot modify player NBT. NBT data inside the  key of items in the player's   or  are an exception and can be modified by "/execute store ".
 * Use the scoreboard under and to save the return value.
 * must exist, but unlike with "/stats" you don't need to set an initial value for.
 * Test for some condition before choosing whether to carry out the command.
 * Compares the block at the given position to the given block ID
 * Compare region between the and positions to the block located at the position.
 * Execute if or unless the targeted entity or block has any data for the tag named by.
 * &mdash;Names an NBT to check for. This is a string of parent tag names of the Java-like form.
 * Example:.
 * means foo's child called bar.
 * means element 0 of bar.
 * "quoted strings" may be used if a name of a key needs to be escaped.
 * Example:  would test for if any entity has an "id" for the item in their boot armour slot. Note that this returns true for all mobs, armoured or not.
 * Execute if or unless one or more exist.
 * Execute if or unless the target entity's score accurately relates to source entity's score, given some conditional operator.
 * Execute if or unless target entity's score is within given range (e.g.,  ).
 * See 10.  above.
 * Test for some condition before choosing whether to carry out the command.
 * Compares the block at the given position to the given block ID
 * Compare region between the and positions to the block located at the position.
 * Execute if or unless the targeted entity or block has any data for the tag named by.
 * &mdash;Names an NBT to check for. This is a string of parent tag names of the Java-like form.
 * Example:.
 * means foo's child called bar.
 * means element 0 of bar.
 * "quoted strings" may be used if a name of a key needs to be escaped.
 * Example:  would test for if any entity has an "id" for the item in their boot armour slot. Note that this returns true for all mobs, armoured or not.
 * Execute if or unless one or more exist.
 * Execute if or unless the target entity's score accurately relates to source entity's score, given some conditional operator.
 * Execute if or unless target entity's score is within given range (e.g.,  ).
 * See 10.  above.
 * Execute if or unless one or more exist.
 * Execute if or unless the target entity's score accurately relates to source entity's score, given some conditional operator.
 * Execute if or unless target entity's score is within given range (e.g.,  ).
 * See 10.  above.
 * Execute if or unless target entity's score is within given range (e.g.,  ).
 * See 10.  above.
 * See 10.  above.


 * Examples



Bedrock Edition

 * Syntax


 * An alternate syntax allows the command to be executed only if a specific block is detected:
 * An alternate syntax allows the command to be executed only if a specific block is detected:

Color added to make reading easier.


 * Arguments


 * origin: target
 * 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 will be run once as each of them.
 * position: x y z
 * Specifies the position from which to run the command. x and z must be within the range -30,000,000 to 30,000,000 (inclusive). Coordinates specified with tilde notation are relative to the target, not to the position of the command's execution.
 * command: command
 * Specifies the command to be run. Must be a valid command.
 * detectPos: x y z ( mode only)
 * Specifies the position of the block to check. x2 and z2 must be within the range -30,000,000 to 30,000,000 (inclusive). May use tilde notation to specify distances relative to (x,y,z).
 * block: Block ( mode only)
 * Specifies the block ID which the block at (x2,y2,z2) must match for the command to run. block must be a valid block id (for example, )
 * data: int ( mode only)
 * Must be a valid block data for that type of block or  to match any block data.


 * Result


 * Fails if arguments are not specified correctly, if fails 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:
 * To summon lightning bolts at the positions of every zombie standing on any type of sand:
 * To summon 10 creepers at the nearest player's position (only works as long as there are at least 10 entities in the loaded world):
 * To summon 10 creepers at the nearest player's position (only works as long as there are at least 10 entities in the loaded world):
 * To summon 10 creepers at the nearest player's position (only works as long as there are at least 10 entities in the loaded world):

History
Befehl/execute 命令/execute