# shelle
[](https://crates.io/crates/shelle)
[](https://opensource.org/licenses/MIT)
Macros for writing shell scripts in Rust.
This project is based on [cmd_lib](https://github.com/rust-shell-script/rust_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:
```rust
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";
// 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:
```rust
let version = shelle::eval!(rustc --version)?;
println!("Your rust version is {}", version);
// with pipes
```