MiniBench

MiniBench / Learn / Commands

Command Bedrock Edition ~3 min read

The /execute command

Run another command as someone else, somewhere else, or only if a condition is true. The most powerful command there is.

What it does

/execute doesn't do much on its own — it changes the context that another command runs in. You chain subcommands (who runs it, where, and under what conditions), then finish with run <command>. It's the backbone of almost every advanced pack.

Syntax

execute <subcommand> ... run <command>
as <target>
Run as each matched entity (changes who @s is).
at <target>
Run at the target’s position and rotation.
positioned <x y z>
Run at a specific position.
if / unless
Only run when a condition holds — if block, if entity, and more.
run <command>
The command to run in the built-up context.

Examples

execute as @a at @s run setblock ~ ~-1 ~ glass

Put a glass block under every player’s feet.

execute at @p run summon lightning_bolt ~ ~ ~

Strike lightning at the nearest player’s position.

execute if block ~ ~-1 ~ water run say You are over water

Only say the message when there’s water below.

See it in action

Before and after running /execute — in MiniBench's 3D preview and in Minecraft.

Command run

execute as @s at @s run fill ~-1 ~ ~8 ~1 ~2 ~10 emerald_block
In Minecraft
/execute running a nested command to place blocks in Minecraft (before)

Before

/execute running a nested command to place blocks in Minecraft (after)

After

Not affiliated with Mojang or Microsoft. Minecraft is a trademark of Mojang Synergies AB.

Watch out for

Write it in MiniBench with autocomplete and live validation, then run it in Minecraft.