| Crates.io | bashrs |
| lib.rs | bashrs |
| version | 6.57.0 |
| created_at | 2025-07-07 16:31:37.763566+00 |
| updated_at | 2026-01-20 11:13:15.198945+00 |
| description | Rust-to-Shell transpiler for deterministic bootstrap scripts |
| homepage | https://github.com/paiml/bashrs |
| repository | https://github.com/paiml/bashrs |
| max_upload_size | |
| id | 1741536 |
| size | 10,393,620 |
Bidirectional shell safety tool that purifies legacy bash scripts and lets you write shell scripts in REAL Rust with automatic safety guarantees.
Latest Release - 2026-01-06
sc2086_logic.rs: Double-quote detection (37 unit tests)sc2154_logic.rs: Variable reference validation (44 unit tests)devcontainer_logic.rs: JSON validation helpers (42 unit tests)sec010_logic.rs: Path traversal detection (26 unit tests)make coverage runs in under 5 minutes with nextestSee CHANGELOG.md for complete release notes.
Shell scripts are everywhere—CI/CD pipelines, deployment automation, system configuration—but they're notoriously difficult to write safely. Rash solves this by providing:
| What ShellCheck Does | What Rash Does |
|---|---|
| ⚠️ Warns: "$RANDOM is non-deterministic" | ✅ Rewrites to version-based deterministic IDs |
| ⚠️ Warns: "mkdir may fail if exists" | ✅ Transforms to mkdir -p (idempotent) |
| ⚠️ Warns: "Unquoted variable expansion" | ✅ Quotes all variables automatically |
| Static pattern matching | Full AST semantic understanding |
| Detects issues (read-only) | Fixes issues (read-write transformation) |
Key Difference: ShellCheck tells you what's wrong. Rash understands your code's intent and rewrites it to be safe, deterministic, and idempotent — automatically.
# From crates.io (recommended)
cargo install bashrs
# Or from source
git clone https://github.com/paiml/bashrs
cd bashrs
cargo install --path rash
// install.rs
#[rash::main]
fn main() {
let version = env_var_or("VERSION", "1.0.0");
let prefix = env_var_or("PREFIX", "/usr/local");
echo("Installing MyApp {version} to {prefix}");
mkdir_p("{prefix}/bin");
mkdir_p("{prefix}/share/myapp");
if exec("cp myapp {prefix}/bin/") {
echo("âś“ Binary installed");
} else {
eprint("âś— Failed to install binary");
exit(1);
}
}
Transpile to safe POSIX shell:
$ bashrs build install.rs -o install.sh
Before (messy bash):
#!/bin/bash
SESSION_ID=$RANDOM # Non-deterministic
mkdir /app/releases/$RELEASE # Non-idempotent
rm /app/current # Fails if doesn't exist
After (purified by Rash):
#!/bin/sh
session_id="session-${version}" # âś… Deterministic
mkdir -p "/app/releases/${release}" # âś… Idempotent
rm -f "/app/current" # âś… Safe removal
# Transpile Rust to shell
bashrs build input.rs -o output.sh
# Purify legacy bash scripts
bashrs purify messy.sh -o clean.sh
# Interactive REPL with debugging
bashrs repl
# Lint shell scripts (including Dockerfiles)
bashrs lint script.sh
# Test bash scripts
bashrs test script.sh
# Quality scoring
bashrs score script.sh
# Comprehensive audit
bashrs audit script.sh
Rash includes Probar integration for comprehensive quality assurance:
# State machine testing with playbooks
bashrs playbook install.playbook.yaml --run
# Mutation testing (goal: >90% kill rate)
bashrs mutate script.sh --count 10
# Deterministic simulation replay
bashrs simulate script.sh --seed 42 --verify
Mutation Operators: Rash applies 10 mutation operators including string mutations, command substitutions, conditional inversions, and redirect modifications to verify test quality.
The Rash Book is the canonical source for all documentation:
Quick links:
Why the book?
| Metric | Value | Status |
|---|---|---|
| PMAT Score | 133/134 (99.3%) | âś… Grade A+ |
| Tests | 9,824 passing | âś… 100% pass rate |
| Line Coverage | 94.16% | âś… Near target (95%) |
| Function Coverage | 96.52% | âś… Exceeds target |
| T-code Falsification | 142/142 | âś… 130-point checklist |
| D-code Falsification | 31/31 | âś… Dockerfile validation |
| ShellCheck | 100% compliant | âś… All output passes |
| Shell Compatibility | 6 shells | âś… sh, dash, bash, ash, zsh, mksh |
Rash uses Popperian falsification—tests attempt to disprove functionality rather than prove it works:
# Run 130-point transpiler falsification checklist
cargo test -p bashrs --test transpiler_tcode_tests
# Run 30-point Dockerfile falsification checklist
cargo test -p bashrs --test dockerfile_dcode_tests
A passing test means the falsification attempt failed—the feature works correctly.
Generated scripts are tested on:
| Shell | Version | Status |
|---|---|---|
| POSIX sh | - | âś… Full support |
| dash | 0.5.11+ | âś… Full support |
| bash | 3.2+ | âś… Full support |
| ash (BusyBox) | 1.30+ | âś… Full support |
| zsh | 5.0+ | âś… Full support |
| mksh | R59+ | âś… Full support |
Rash is designed for fast transpilation:
Rash provides a Model Context Protocol (MCP) server for AI-assisted shell script generation:
# Install MCP server
cargo install rash-mcp
# Run server
rash-mcp
Available in the official MCP registry as io.github.paiml/rash.
We welcome contributions! See our Contributing Guide for details.
# Clone and test
git clone https://github.com/paiml/bashrs.git
cd bashrs
make test
# Run all quality checks
make validate
MIT License. See LICENSE for details.