Skip to content
Latchkey

bun exec: Run a Command Through Bun Shell

bun exec runs a command string through Bun's cross-platform shell directly from the command line.

bun exec is the CLI front door to Bun Shell. Where bun run executes a package script and bunx runs a package binary, bun exec runs an arbitrary shell command string portably.

What it does

bun exec "<command>" parses and runs the command string with Bun's built-in shell, the same engine behind the $... template. It gives you portable pipelines and builtins from the terminal without writing a script file, and without depending on the host's bash or PowerShell.

Common usage

Terminal
bun exec "echo hello && ls -1"
bun exec "cat package.json | grep name"
bun exec "rm -rf dist && mkdir dist"

Options

FormWhat it does
bun exec "<cmd>"Run the command string via Bun Shell
(pipes / &&)Supported through the built-in shell
vs bun runrun executes a package.json script, not a raw command
vs bunxbunx runs a package binary; exec runs a shell command

In CI

Use bun exec for portable one-liners in pipelines that must run on both Linux and Windows runners without branching on the OS. For multi-step logic prefer a script file run with bun run, which is easier to test. Keep secrets out of the command string since CI logs may capture it.

Common errors in CI

"command not found" means an external binary is not on PATH on that runner; Bun Shell shells out for non-builtins. A non-zero exit from the command propagates as a non-zero exit from bun exec, which fails the CI step as intended. Bash-only syntax that Bun Shell does not support will fail to parse; use the supported subset or move to a script file.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →