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