Back to articles
Bun Shell Has a Built-in Shell Scripting Language — Here's How to Use It

Bun Shell Has a Built-in Shell Scripting Language — Here's How to Use It

via Dev.to WebdevAlex Spinov

Bun introduced something most JavaScript developers never expected — a built-in shell scripting language that runs cross-platform. What is Bun Shell? Bun Shell ( Bun.$ ) is a cross-platform shell built into the Bun runtime. It lets you run shell commands using tagged template literals with full JavaScript interop. Quick Start import { $ } from " bun " ; // Run any shell command await $ `echo Hello from Bun Shell!` ; // Capture output const result = await $ `ls -la` . text (); console . log ( result ); // Use JavaScript variables seamlessly const dir = " ./src " ; await $ `find ${ dir } -name "*.ts" | wc -l` ; Why Bun Shell Matters 1. Cross-Platform by Default // This works on macOS, Linux, AND Windows await $ `echo $HOME` ; // Uses Bun's built-in shell, not system shell await $ `cat file.txt | grep pattern` ; 2. JavaScript Interop const files = [ " a.txt " , " b.txt " , " c.txt " ]; for ( const file of files ) { await $ `cat ${ file } >> combined.txt` ; } // Pipe to JavaScript const ou

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles