Skip to main content
Run shell scripts directly with Bun’s cross-platform shell.
bun exec <script>

Basic Usage

Execute a shell script:
bun exec "echo 'Hello World'"
Run a script file:
bun exec ./script.sh

Cross-Platform Shell

Bun’s shell works on Windows, macOS, and Linux:
bun exec "ls -la && echo 'Done'"
This works on all platforms, including Windows (no bash required).

Features

  • Cross-platform compatibility
  • Pipes and redirects
  • Environment variable expansion
  • Command substitution

Examples

Pipes

bun exec "echo 'test' | grep 'test'"

Redirects

bun exec "echo 'Hello' > output.txt"
bun exec "cat < input.txt"

Environment Variables

bun exec "echo $HOME"
bun exec "export VAR=value && echo $VAR"

Command Substitution

bun exec "echo $(date)"

vs Shell Scripts

Use bun exec for:
  • Cross-platform scripts
  • Simple automation
  • CI/CD pipelines
Use regular shell scripts for:
  • Complex bash features
  • System administration
  • Platform-specific tasks

$ Shell in TypeScript

For programmatic shell usage in TypeScript, use Bun’s $ API:
import { $ } from "bun";

const result = await $("ls -la");
console.log(result.stdout);
See Shell API for details.

Next Steps

Shell API

Use $ shell in TypeScript

bun run

Run JavaScript files

Build docs developers (and LLMs) love