| Crates.io | shelle-macros |
| lib.rs | shelle-macros |
| version | 0.1.1 |
| created_at | 2025-06-25 21:34:46.716693+00 |
| updated_at | 2025-06-27 16:16:12.941327+00 |
| description | Proc macros for shelle |
| homepage | |
| repository | https://github.com/foltik/shelle |
| max_upload_size | |
| id | 1726469 |
| size | 23,958 |
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.
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);