bash-web
v0.0.114
Published
WASM-first bash-compatible shell
Readme
Experimental and pre-1.0. Not on npm. Build from source. Status lists what works and what does not.
Run a script on the engine, natively, with no browser:
$ shell/target/release/shell-engine -c '
greet() { echo "hello, $1"; }
for name in web wasm; do greet "$name"; done
words=(a b c)
echo "${#words[@]} words, first is ${words[0]}"
printf "%q\n" "two words"
echo $((6 * 7))
seq 3; echo "seq exited $?"
'
hello, web
hello, wasm
3 words, first is a
two\ words
42
seq exited 127
/usr/bin/bash: seq: command not foundRun the same engine in a page. This needs a built checkout, Waffle at the version bash-web selects, installed as waffle@npm:@waffle-os/runtime (Waffle's API is early and can change), and dist/fs-worker.js served at /fs-worker.js. Embed a shell in a page has the install steps.
import { createRuntime } from "waffle";
import { createShell } from "bash-web";
const runtime = createRuntime({
filesystem: { workerURL: new URL("/fs-worker.js", location.href) },
});
const shell = await createShell({ runtime, script: "echo hello" });
const { code } = await shell.done; // output arrives in shell.terminal
await shell.dispose();
await runtime.dispose();Why
- Bash behavior, measured. GNU Bash 5.3.15 is the oracle. The committed baseline passes 1,315 of 1,682 Oils builtins-only cases (78.2%), comparing stdout bytes and exit status, and CI fails any change that stops a passing case from passing. Reproduce it.
- Pipelines stream. Every pipeline stage is a task on one thread, and pipes are bounded.
producer | grepshows lines as they arrive, and Ctrl+C stops the foreground job without touching background jobs. - You pay for the commands you use. The shell core has no external commands.
cat,grep,mkdir, andseqare separate WASM programs that you install on demand. Anything not installed exits 127. - One runtime per page. The shell borrows your Waffle runtime. It never creates one, and disposing a shell leaves the runtime and other shells alone.
The page creates the runtime and createShell borrows it. The terminal is two byte rings between the page and the worker.
Quick start
You need git and Rust through rustup, because the repository pins its Rust version in rust-toolchain.toml and rustup installs that version.
Clone and build the engine:
git clone https://github.com/ShaulLavo/bash-web.git cd bash-web cargo build --release --locked --manifest-path shell/Cargo.toml -p shell-engine --bin shell-engineRun a script:
shell/target/release/shell-engine -c 'echo hello; exit 7'; echo "exit: $?"hello exit: 7
Getting started continues with pipelines and the utilities. The browser build also needs wasi-sdk 34.0 to compile the WASM guests. Start with Embed a shell in a page.
What you can do
- Build the engine and try scripts: Getting started
- Run a script or an interactive shell in a page: Embed a shell in a page
- Add
cat,grep,mkdir, andseq: Install utilities - Fix
command not foundor a blank page: Troubleshooting
How it works
The shell is a WASM program, not a runtime. A thin TypeScript adapter starts it in a worker on the Waffle runtime your page created. The page and the worker share a SharedArrayBuffer with an input ring and an output ring, so the page never blocks on the shell. The engine runs one async executor on one thread, and every pipeline stage, subshell, and background job is a task. External commands run as other WASM programs that Waffle starts with the right descriptors. How bash-web works explains the design and its three ADRs record why.
Docs
Docs map · Getting started · Guides · Concepts · API reference · Status and limits · ADRs · Development
Status
Experimental and pre-1.0. The version is 0.0.x, the package is private, and there are no releases. Any commit can change the API.
- Native engine: builds and tests on macOS arm64 and Linux.
- WASI guests and browser build: Linux only (CI). Not verified on macOS or Windows.
- Browsers: Chromium and Firefox in CI. Safari is not verified.
- Bash compatibility: 78.2% of Oils builtins-only cases. Missing: associative arrays,
mapfile, running traps, printf floats. - Bun: not included. The Bun-specific browser tests are skipped.
Every gap, with a command that shows it, is in Status and limits.
License
MIT. The parser and several expansion rules started from Bashkit (MIT). See third-party notices.
Contributing
Build, test, and layout notes are in Development.
