shelle 0.1.1

Macros for writing shell scripts in Rust.
Documentation
  • Coverage
  • 14.81%
    4 out of 27 items documented0 out of 0 items with examples
  • Size
  • Source code size: 16.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.76 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • foltik/shelle
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • foltik

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);