Bun Shell ($) in Bun

From the Bun cheat sheet ยท Shell & Child Processes ยท verified Jul 2026

Bun Shell ($)

Run shell commands with tagged template literals

typescript
import { $ } from "bun";

// Run a command
await $`echo "Hello World"`;

// Capture output
const result = await $`ls -la`.text();

// Use variables safely (auto-escaped)
const dir = "/tmp";
await $`ls ${dir}`;
๐Ÿ’ก Bun.$ auto-escapes interpolated variables โ€” safe from shell injection by default
โšก Use .nothrow() to prevent throwing on non-zero exit codes โ€” check exitCode instead
๐Ÿ“Œ Bun Shell works cross-platform โ€” same syntax on macOS, Linux, and Windows
๐ŸŸข Chain .text(), .json(), or .lines() to parse command output in one call
shellcommandspawn

More Bun tasks

Back to the full Bun cheat sheet