macro_rules! bash_command {
    ($s:expr) => { ... };
    ($s:expr, $( $id:ident = $v:expr),*) => { ... };
    ($s:expr, $( $id:ident ),*) => { ... };
}
Expand description

Create a Command object that will execute a fragment of (Bash) shell script in “strict mode”, i.e. with set -euo pipefail. The first argument is the script, and additional arguments should be Rust variable identifiers. The provided Rust variables will become shell script variables with their values quoted.

This macro will allocate a temporary file for the script; this can (in very unusual cases such as file descriptior exhaustion) fail.

use sh_inline::*;
let a = "foo";
let b = std::path::Path::new("bar");
let c = 42;
let d: String = "baz".into();
let r = bash_command!(r#"test "${a} ${b} ${c}" = "foo bar 42""#, a, b, c).expect("creating script").status()?;
assert!(r.success());
let r = bash_command!(r#"test "${a}" = "2""#, a = 1 + 1).expect("creating script").status()?;
assert!(r.success());