Commands/execute

is a versatile command that modifies variables or procedures in the execution of another command, such as giving the server a false impression of the entity that's executing the command, its current position, how it's rotated, etc.

All commands end up having a success status and some quantifiable value they can return to a target, as might be specified by. All commands issued from command blocks return the success status to that issuing command block, which can trigger chained command blocks.

Java Edition

 * Syntax

There are twelve instructions (or sub-commands) for the  command, and each has its own special syntax, so describing syntax takes a large 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow 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—an exception is that including the   or   instructions allow this terminator to be left out.


 * Details


 * There are 11 chainable instructions—9 instructions that modify command variables and 2 conditional instructions—and a final  instruction for carrying out some following command. A number of instructions can be chained together, but   finalizes 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 (toward negative infinity).
 * —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 "/execute align xz run summon zombie ~ ~ ~" summons a zombie at (-2.0, +2.3, +5.0).
 * Example: Given (+2.4, -1.1, +3.8), using "/execute align yxz run spawnpoint @p ~ ~ ~" sets the player's spawnpoint to (2, -2, 3).
 * Stores the distance from the feet to the eyes of the entity that is executing the command in the anchor, which is part of the command context.
 * The only places where the anchor is used is in the caret notation and in the   subcommand of the   command, which behave as if the executing position was shifted upward by the stored value.
 * Execute the command as the targeted entity/entities, but does not change position.
 * Changes the function of the  target selector variable
 * Use the position, rotation, and dimension of the target, but does not change the current executing entity.
 * Changes the function of  and   positioning
 * Use an execution position that faces either the given position or the targeted entity's eyes or feet.
 * Changes the function of  positioning
 * Execute as though the executor is in the given dimension.
 * Changes command dimension, but does not affect X- Y- Z-positions
 * —The standard dimensions in the Minecraft namespace are "overworld", "the_nether", and "the_end".
 * Use either the given coordinates or the targeted entity's coordinates for the "current position."
 * Changes the function of  and   positioning. Does not change rotation, dimension, or target of.
 * Execute as though the executor is rotated either in the given direction or the same the targeted entity is facing.
 * Changes command rotation
 * Store the result or success of a command somewhere. This instruction replaced the "/stats" command.
 * —Return the result of the command. (This replaces the old stats AffectedBlocks, AffectedEntities, AffectedItems, QueryResult.)
 * —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 . The return value is stored when the full command has finished executing.
 * Saves the return value in NBT data at the given block position.
 * —Name of the data tag to save return value in. See 10.  below for more details.
 * Saves the return value in either the current value or the maximum value of the given bossbar
 * —ID of the bossbar to store return value in.
 * —Specifies that the bossbar's "value" is to be overwritten with the execution's return value
 * —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.
 * 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 .
 * Uses the  within storage  to store the return value in.
 * If the storage does not yet exist, it gets created.
 * —Target storage container, as a namespaced ID.
 * —Name of the data tag to save return value in. See 10.  below for more details.
 * 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 area starting at the position. The calculation of the areas as well as the  argument work in the same way as they do in the  command.
 * Execute if or unless the targeted block, entity or storage has any data for the tag named by .
 * —Names an NBT to check for. This is a string of parent tag names of the Java-like form.
 * See Commands/data for more on paths
 * Example:  would test for if any entity has an "id" for the item in their boot armor slot. Note that this returns true for all mobs, armored or not.
 * Execute if or unless one or more  exist.
 * Execute if or unless the  evaluates to a positive result.
 * See Predicate for more on predicates
 * 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.
 * —Target storage container, as a namespaced ID.
 * —Name of the data tag to save return value in. See 10.  below for more details.
 * 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 area starting at the position. The calculation of the areas as well as the  argument work in the same way as they do in the  command.
 * Execute if or unless the targeted block, entity or storage has any data for the tag named by .
 * —Names an NBT to check for. This is a string of parent tag names of the Java-like form.
 * See Commands/data for more on paths
 * Example:  would test for if any entity has an "id" for the item in their boot armor slot. Note that this returns true for all mobs, armored or not.
 * Execute if or unless one or more  exist.
 * Execute if or unless the <predicate> evaluates to a positive result.
 * See Predicate for more on predicates
 * 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 the <predicate> evaluates to a positive result.
 * See Predicate for more on predicates
 * 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.
 * See 10.  above.


 * Beyond those 11 instructions, there's the  instruction.
 * Specifies the command to be executed, the variables of which may be modified by the subcommands used.
 * Can be any Minecraft command
 * Technical: Resets the command node to the root of the command dispatcher
 * Modelling commands as chat text...
 * The command dispatcher is what starts when the player begins a message with a forward-slash.
 * A command node is the specific word/entry your cursor is editing, either a command or an argument.
 * The root node comes before the first word in your command.
 * The root node comes before the first word in your command.


 * 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 is 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 that 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