shelle-macros

Crates.ioshelle-macros
lib.rsshelle-macros
version0.1.1
created_at2025-06-25 21:34:46.716693+00
updated_at2025-06-27 16:16:12.941327+00
descriptionProc macros for shelle
homepage
repositoryhttps://github.com/foltik/shelle
max_upload_size
id1726469
size23,958
Jack Foltz (foltik)

documentation

README

shelle

Crates.io License: MIT

Macros for writing shell scripts in Rust.

This project is based on cmd_lib. Thanks to @tao-guo and other contributors for your hard work.

Usage

shelle::exec!() runs command(s) with stdin/stdout/stderr inherited from the main program:

let msg = "I love rust";
shelle::exec!(echo #msg)?;
shelle::exec!(echo "This is the message: #msg")?;

// pipe commands are also supported
let dir = "/var/log";
shelle::exec!(du -ah #dir | sort -hr | head -n 10)?;

// or a group of commands
// if any command fails, just return Err(...)
let file = "/tmp/f";
let keyword = "rust";
shelle::exec! {
    cat #{file} | grep #{keyword};
    echo "bad cmd" >&2;
    ignore ls /nofile;
    date;
    ls oops;
    cat oops;
}?;

shelle::eval!() runs command(s) with stdout piped to a string, and stdin/stderr inherited from the main program:

let version = shelle::eval!(rustc --version)?;
println!("Your rust version is {}", version);

// with pipes
let n = shelle::eval!(echo "the quick brown fox jumped over the lazy dog" | wc -w)?;
println!("There are {} words in above sentence", n);
Commit count: 0

cargo fmt