Skip to content

paiml/bashrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

bashrs

Rash - Bidirectional Shell Safety Tool

Crates.io Documentation Book License CI

Bidirectional shell safety tool that purifies legacy bash scripts and lets you write shell scripts in REAL Rust with automatic safety guarantees.

Table of Contents

πŸš€ What's New in v6.44.0

Latest Updates - 2025-12-16

  • Complete Parser Bug Fixes: All 23 parser bugs found via probar TUI testing have been fixed (100%)
    • P0 Critical (5/5): Nested parameter expansion, negative arithmetic, ternary, bitwise, empty assignment
    • P1 High (8/8): Heredocs, case fall-through/resume, function names with dashes, array operations
    • P2 Medium (10/10): Coproc, extended globs, redirect operators, deep nesting
  • New coproc Keyword: Full coprocess syntax support (coproc NAME { cmd; })
  • Function Subshell Bodies: myfunc() ( cmd ) syntax now works
  • Glob Pattern Fixes: [abc].txt, [!abc] character class globs now parse correctly
  • Test Suite: 7,365 tests, 100% pass rate, zero regressions

See CHANGELOG.md for complete release notes.

Why Rash?

Features

  • πŸ›‘οΈ Automatic Safety: Protection against shell injection, word splitting, glob expansion
  • πŸ” Beyond Linting: Full AST semantic understanding - transforms code, doesn't just warn
  • πŸ“¦ Zero Runtime Dependencies: Generated scripts work on any POSIX shell
  • 🎯 Deterministic Output: Same input always produces identical scripts
  • βœ… ShellCheck Compliant: All output passes strict linting

How Rash Exceeds ShellCheck

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.

Quick Start

Installation

# From crates.io (recommended)
cargo install bashrs

# Or from source
git clone https://github.com/paiml/bashrs
cd bashrs
cargo install --path rash

Write Rust, Get Safe Shell

// 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

Or Purify Existing Bash

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

Core Commands

# 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
bashrs lint script.sh

# Test bash scripts
bashrs test script.sh

# Quality scoring
bashrs score script.sh

# Comprehensive audit
bashrs audit script.sh

πŸ“š Documentation

The Rash Book is the canonical source for all documentation:

Quick links:

Why the book?

  • βœ… All examples automatically tested
  • βœ… Always up-to-date with latest release
  • βœ… Comprehensive coverage of all features
  • βœ… Real-world examples and tutorials

Quality Metrics (v6.41.0)

Metric Status
Quality Grade A+ (Near Perfect) βœ…
Tests 6,583 passing (0 failures) βœ…
Coverage 88.71% (exceeds 85% target) βœ…
Mutation Testing 92% kill rate βœ…
Property Tests 52+ properties (~26k+ cases) βœ…
ShellCheck 100% compliant βœ…
Shell Compatibility sh, dash, bash, ash, zsh, mksh βœ…
Golden Traces Renacer integration for regression detection βœ…

Golden Trace Regression Detection (v6.36.0+)

Rash integrates with renacer to capture and compare syscall patterns for regression detection:

# Capture reference trace
make golden-capture TRACE=version CMD='./target/release/bashrs --version'

# Compare against golden (detect regressions)
make golden-compare TRACE=version CMD='./target/release/bashrs --version'

Use cases:

  • Detect unexpected file access patterns
  • Prevent security regressions
  • Verify performance optimizations reduce syscalls
  • Ensure deterministic behavior across builds

See Golden Trace Documentation for complete guide.

Shell Compatibility

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

Performance

Rash is designed for fast transpilation:

  • Rust-to-Shell: 21.1Β΅s transpile time
  • Makefile Parsing: 0.034-1.43ms (70-320x faster than targets)
  • Memory Usage: <10MB for most scripts

MCP Server

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.

Contributing

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

License

Rash is licensed under the MIT License. See LICENSE for details.

Acknowledgments

Rash is built with safety principles inspired by:

  • ShellCheck for shell script analysis
  • Oil Shell for shell language design
  • The Rust community for memory safety practices

For comprehensive documentation, tutorials, and examples, visit The Rash Book.

About

Bashrs: Rust-to-Shell Transpiler for Deterministic Bootstrap Scripts

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •