Skip to main content

Run a Shell Command

还没翻译译自英文(bun.com)本页 6 段都还没译

Bun Shell is a cross-platform bash-like shell built into Bun.

It runs shell commands from JavaScript and TypeScript. To get started, import the $ function from the bun package.

import { $ } from "bun";

await $`echo Hello, world!`; // => "Hello, world!"

The $ function is a tagged template literal that runs the command and returns a promise that resolves with the command's output.

import { $ } from "bun";

const output = await $`ls -l`.text();
console.log(output);

To iterate over each line of the output, use the lines method.

import { $ } from "bun";

for await (const line of $`ls -l`.lines()) {
  console.log(line);
}

See Bun Shell.

번역 © 2026 fanyi.dev · 원문 © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)