Typorithm · medium

Bun Shell ($)

bun-shellbunshellinterpolationpipes
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Bun Shell ($)

0%

System & FFI

Bun Shell exports a $ tag from "bun" that runs shell commands cross-platform. Await $`cmd`.text() to capture stdout, use .quiet() to silence it, and rely on auto-escaped ${interpolation}. Pipes and redirects work without a real system shell.

import { $ } from "bun" gives you a tagged-template shell: await $`ls -la` runs the command, and the same code works on macOS, Linux, and Windows because Bun parses the script itself.

Chain .text() to get stdout as a string or .quiet() to run silently; values you interpolate with ${} are automatically escaped, so user input never breaks out into shell injection.

Familiar shell features carry over — pipe with |, redirect with > — but they are implemented by Bun rather than handed to /bin/sh, keeping behaviour consistent across platforms.

01

import { $ } from "bun"; await $`cmd` runs a command.

02

.text() captures stdout; .quiet() silences output.

03

${interpolation} is auto-escaped against injection.

import { $ } from "bun";
const files = await $`ls -la`.text();
const name = "my file.txt";
await $`cat ${name}`.quiet();
await $`echo hello | grep h > out.txt`;

Read the implementation

Connect each part of the code to the concept before you type.

1. Import the shell

The $ tag is exported from "bun" and runs shell commands cross-platform with no extra dependency.

import { $ } from "bun";

2. Capture output

Awaiting $`...`.text() runs the command and resolves to its stdout as a string.

const files = await $`ls -la`.text();

3. Safe interpolation

Interpolated ${values} are auto-escaped, so a filename with spaces is passed as a single safe argument.

await $`cat ${name}`.quiet();

4. Silence output

.quiet() runs the command without echoing its output to the terminal.

.quiet()

5. Pipe and redirect

Pipes (|) and redirects (>) work just like a real shell, but cross-platform via Bun's own parser.

await $`echo hello | grep h > out.txt`;

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Bun Shell ($): Lesson & Practice · Typorithm | ApplyDjinn