Files

43 lines
907 B
Plaintext
Raw Permalink Normal View History

2026-08-27 21:09:14 +00:00
---
title: Run a Shell Command
sidebarTitle: Run shell command
mode: center
---
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.
```ts foo.ts icon="/icons/typescript.svg"
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.
```ts foo.ts icon="/icons/typescript.svg"
import { $ } from "bun";
const output = await $`ls -l`.text();
console.log(output);
```
---
To iterate over each line of the output, use the `lines` method.
```ts foo.ts icon="/icons/typescript.svg"
import { $ } from "bun";
for await (const line of $`ls -l`.lines()) {
console.log(line);
}
```
---
See [Bun Shell](/runtime/shell).