Commands/execute

is a versatile command that modifies variables or procedures in the execution of another command.

Java Edition
$$, there are twelve instructions (or sub-commands) for the  command. Multiple sub-commands are connected after /execute. Subcommands are divided into 4 categories: modify subcommands, condition subcommands, store subcommands, and  subcommand.
 * Modify subcommands modify command variables and change the situation the command is executed, and execute subcommands following it with specific executor(s), execution position(s), execution dimension(s), and execution rotation(s).
 * Condition subcommands are used to test whether certain conditions are true and output results or limit conditions of execution.
 * Store subcommands can store the return values of the command in a scoreboard or the data of an entity, block entity or storage, and can also change the maximum or current value of a boss bar.
 * subcommand is used for carrying out another command.

A number of sub-commands needed can be chained together. Subcommands other than the  subcommand can be arranged arbitrarily or used multiple times. But the  subcommand can only be used once and must at the end of the subcommands chain. A  subcommand or a condition subcommand finalizes the command, otherwise the command does nothing. The game processes these subcommands in order from front to end, for example, the following commands are different:
 * All entities move one block forward:
 * All entities move to one block in front of the executor:

The game processes other subcommands before processing  and store subcommands, so the   and store subcommands cannot affect other subcommands. The  commands and store subcommands cannot affect each other as well. In some cases, the command terminates halfway and does nothing.

After the command is executed (if it does not terminate halfway), it returns a  and a   value (see  for details). These two values ​​come from the last subcommand (may be a condition subcommand or  subcommand). Note that the return value of the command must be an integer, if not, it is rounded down. The  value is usually 0 or 1. When the command fails, both return values ​​are 0. When the last subcommand (may be a condition subcommand or  subcommand) is executed multiple times, only values of the last execution can be returned. The two values can be stored by store subcommands.

command also has a success count (whether or not terminates halfway). 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. When executing it with the command block, the success count is returned to the command block, which can be checked by the conditional command block for success or be read with a redstone comparator.

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.


 * Full syntax tree:
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.

align
Convert execution position's coordinates of specified axes to block position (rounding down, toward negative infinity.).
 * Syntax
 * Arguments
 * Any non-repeating combination of the characters 'x', 'y', and 'z'. (For example,,  ,  , or  .)
 * Result
 * Error if the argument is not specified correctly.
 * Example
 * Given the position (-1.8, +2.3, +5.9), the command  summons a zombie at (-2.0, +2.3, +5.0).
 * Given (+2.4, -1.1, +3.8), using  sets the player's spawnpoint to (2, -2, 3).
 * Given the position (-1.8, +2.3, +5.9), the command  summons a zombie at (-2.0, +2.3, +5.0).
 * Given (+2.4, -1.1, +3.8), using  sets the player's spawnpoint to (2, -2, 3).

anchor
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. Default of anchor is feet.

The only places where the anchor is used is in the caret notation and in the   subcommand of the   command.
 * Syntax
 * Arguments
 * Must be one of  and.
 * Result
 * Error if the argument is not specified correctly.
 * Result
 * Error if the argument is not specified correctly.

as
Change the executor to the targeted entity/entities, but does not change position or rotation of execution. Changes the function of the  target selector variable
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per executor.
 * Example
 * Get data of all sheep:
 * Example
 * Get data of all sheep:

at
Use the position, rotation, and dimension of the target(s), but does not change the current executor. Changes the function of  and   positioning.
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution position.
 * Example
 * All sheep move upward 1 block:
 * Kill yourself:
 * All sheep move upward 1 block:
 * Kill yourself:

facing
Change the execution rotation to facing either the given position or the targeted entity's/entities' eyes or feet, but does not change the current executor. Changes the function of  positioning.
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Must be one of  and.
 * Must be in form of . May use tilde and caret notation.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution rotation.
 * Example
 * All entities move one block in the direction of (0, 64, 0) (without changing their rotation):
 * All entities move one block in the direction of (0, 64, 0) (with changing their rotation):
 * All non player entities move one space in the direction of their nearest player (without changing their orientation):
 * Example
 * All entities move one block in the direction of (0, 64, 0) (without changing their rotation):
 * All entities move one block in the direction of (0, 64, 0) (with changing their rotation):
 * All non player entities move one space in the direction of their nearest player (without changing their orientation):

in
Change the execution dimension to specified dimension.
 * Syntax
 * Arguments
 * Must be in form of namespaced ID.
 * The standard dimensions in the minecraft namespace are "overworld", "the_nether", and "the_end".
 * Result
 * Error if the argument is not specified correctly.
 * Example
 * Looking for an end city in the end (can find even though players is in the overworld):
 * Transport player to the nether with coordinates unchanged:
 * Looking for an end city in the end (can find even though players is in the overworld):
 * Transport player to the nether with coordinates unchanged:

positioned
Use either the given coordinates or the targeted entity's coordinates for the execution position. Changes the function of  and   positioning. Does not change rotation, dimension, or executor.
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Must be in form of . May use tilde and caret notation.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution position.
 * Example
 * Look for a village near (0, 64, 0):
 * Let all sheep move one block in the direction of the executor's rotation (for example, when the executor looks east, the sheep moves one block eastward; when the executor looks up, the sheep moves one block upward):
 * When multiple entities are selected, next subcommand is executed once each per execution position.
 * Example
 * Look for a village near (0, 64, 0):
 * Let all sheep move one block in the direction of the executor's rotation (for example, when the executor looks east, the sheep moves one block eastward; when the executor looks up, the sheep moves one block upward):

rotated
Change the execution rotation to rotating either in the given direction or the same the targeted entity is facing.
 * Syntax
 * Arguments
 * Specifies the rotation. In form of
 * For the horizontal rotation, -180.0 for due north, -90.0 for due east, 0.0 for due south, 90.0 for due west, to 179.9 for just west of due north, before wrapping back around to -180.0.
 * For the vertical rotation, -90.0 for straight up to 90.0 for straight down.
 * Tilde notation can be used to specify a rotation relative to the current execution rotation.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution rotation.
 * Example
 * Move every sheep 1 block toward the player closest to it:
 * When multiple entities are selected, next subcommand is executed once each per execution rotation.
 * Example
 * Move every sheep 1 block toward the player closest to it:

Syntax and arguments

 * Compares the block at the given position to the given block ID.
 * Specifies a block ID or a block tag, following block states and data tags if needed. See Command.
 * Specifies a block ID or a block tag, following block states and data tags if needed. See Command.


 * 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.
 * ,, and
 * Specifies the coordinates of the two diagonal corner of source region and the coordinates of the northwest lower corner of destination region.
 * Must be in form of . May use tilde and caret notation.
 * Compare all the blocks in regions.
 * Ignore the position where is air in the source region.
 * Ignore the position where is air in the source region.
 * Ignore the position where is air in the source region.


 * Check whether the targeted block, entity or storage has any data for the tag named by.
 * Specifies an NBT path to check for.
 * Specifies an NBT path to check for.


 * Check whether one or more exist.
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Permits entities other than players.


 * Check whether the evaluates to a positive result.
 * See Predicate for more information on predicates


 * Check whether the target entity's score accurately relates to source entity's score, given some conditional operator.


 * Check whether the target entity's score is within given range (e.g.,  ).

General arguments

 * Specifies the coordinates of a block to check.
 * Must be in form of . May use tilde and caret notation.
 * Must be in form of . May use tilde and caret notation.


 * Specifies a single score holder, which can be a player name, a target selector or (commands fails).
 * Specifies a single score holder, which can be a player name, a target selector or (commands fails).


 * Specifies a scoreboard objective.
 * Specifies a scoreboard objective.

Result

 * Error if the argument is not specified correctly.
 * When not at the end of the subcommands chain, Only if the condition tests pass is the subcommand following it executed. If it is executed multiple times by multiple variables (e.g. excuetors, execution positions, execution rotations), it acts as a variable filter - Only the variable that matches the condition executes the next subcommand.
 * When at the end of the subcommands chain, it checks whether the condition is met and then outputs.

Example

 * Kill all players standing on a wool:
 * Check whether your own score a and b are equal:

Store subcommands
Store the   and a   value of a command somewhere.

It first records the location to store in, and then stores in the location after all the commands are executed.

Note that the return values of commands must be an integer. If a decimal, it is rounded down.

Syntax

 * Saves the return value in block entity at the given position. Store as a byte, short, int, long, float, or double. If the return value is a decimal, it is rounded first and then multiplied by.


 * Saves the return value in either the current value or the maximum value of the given bossbar.


 * Use the data tag  from one targeted entity to save the return value. Store as a byte, short, int, long, float, or double. If the return value is a decimal, it is rounded first and then multiplied by.
 * Like the "" command, "/execute store " cannot modify player NBT.


 * Use the scoreboard under and to save the return value.


 * Uses the within storage to store the return value in. Store as a byte, short, int, long, float, or double. If the return value is a decimal, it is rounded first and then multiplied by.
 * If the storage does not yet exist, it gets created.

Arguments

 * Specifies the coordinates of a block entity to store.
 * Must be in form of . May use tilde and caret notation.
 * Must be in form of . May use tilde and caret notation.


 * Specifies an NBT path to store return value in.
 * Specifies an NBT path to store return value in.


 * ID of the bossbar to store return value in.
 * ID of the bossbar to store return value in.


 * in  mode
 * Specifies a single entity, which can be a player name, a target selector or a UUID.


 * Specifies a score holder, which can be a player name, a target selector or.
 * Specifies a score holder, which can be a player name, a target selector or.


 * Specifies a scoreboard objective.
 * Specifies a scoreboard objective.


 * in  mode
 * Target storage container, as a namespaced ID.

Result

 * Error if the argument is not specified correctly.
 * In  and   mode, does not store anything when the path does not exist.

subcommand
Specifies the command to be executed, the variables of which may be modified by the subcommands used.

Arguments

 * Can be any command


 * Technical: Resets the command node to the root of the command dispatcher
 * Information on 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 the cursor is editing, either a command or an argument.
 * The root node comes before the first word in the current command.

Result
Execute this command. Fails if  is failure.

More examples

 * Teleport all players who have an item enchanted with Efficiency in their first hotbar slot to coordinates (0, 64, 0):
 * Create a smoke particle three blocks in front of all players:
 * Place a saddle on pigs located within 5 blocks of the executing player, and remove saddles from pigs located over 5 blocks away from the executing player:
 * Make a player say "My feet are soaked!" in chat if they are located in a block of water:
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":
 * Make a player say "My feet are soaked!" in chat if they are located in a block of water:
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":

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:

Arguments

 * 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.


 * 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.


 * Specifies the command to be run. Must be a valid command.

detectPos: x y z
 * Specifies the position of the block to check. May use tilde and caret notation to specify distances relative to.


 * Specifies the block ID that the block at detectPos, must match for the command to run. Must be a valid block ID.


 * 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 Команди консолі/execute 命令/execute