Skip to main content

Module bun_shell

Module bun_shell 

Source
Expand description

A portable implementation of Bun Shell (Bun.$), ported from Bun’s src/runtime/shell and src/shell_parser and kept behaviour-identical with the JavaScript port in js/src/bun-shell/.

Scripts are written as template literals: strings are the raw template parts and values the interpolated values between them, exactly like $`echo ${name} | cat` in JavaScript:

use command_stream::bun_shell::{shell, ShellValue};

let out = shell(&["echo ", " | cat"], vec![ShellValue::from("world")])?
    .quiet()
    .run()
    .await?;
assert_eq!(out.text(), "world\n");

The conformance corpus in conformance/bun-shell/ is the specification; rust/tests/bun_shell_conformance.rs runs it against this module.

Structs§

OutBuffer
A fixed-size byte buffer that receives output (> ${buf} in JavaScript, where buf is a Uint8Array). Output beyond its size is dropped.
Shell
Default settings for new commands (Bun’s new $.Shell()): each Shell has its own cwd, env and throwing mode.
ShellCommand
A parsed script plus its settings (Bun’s ShellPromise). Nothing runs until ShellCommand::run is awaited.
ShellError
A failed shell invocation.
ShellOutput
The result of a finished script (Bun’s ShellOutput).

Enums§

BraceError
A brace expansion failure.
ShellErrorKind
What kind of failure a ShellError is.
ShellValue
An interpolated template value (the JavaScript value kinds that Bun Shell accepts, minus the JS-only Response/Blob/Bun.file objects).

Functions§

braces
$.braces(pattern): expand a brace pattern into words, e.g. "echo {a,b}" into ["echo a", "echo b"].
escape
$.escape(s): escape a string for use in a script, quoting it when it contains special characters.
shell
Parse a template with the default Shell settings (Bun’s $).