Thursday, February 29, 2024

Bun Shell: JavaScript CLI

 The Bun Shell | Bun Blog

The Bun Shell is a new experimental embedded language and interpreter in Bun that allows you to run cross-platform shell scripts in JavaScript & TypeScript.

import { $ } from "bun";

// to stdout:
await $`ls *.js`;

// to string:
const text = await $`ls *.js`.text();

You can use JavaScript variables in your shell scripts:

import { $ } from "bun";

const resp = await fetch("");

const stdout = await $`gzip -c < ${resp}`.arrayBuffer();

No comments: