Module xshell

Source
Expand description

Shell-like scripting in Rust without invoking a shell.


xshell provides ergonomic subprocess execution with shell-like syntax. It executes commands directly without spawning a shell process, preventing shell injection vulnerabilities while providing variable interpolation in the cmd! macro.

Useful for build scripts, CLI tools, and automation tasks.

§Examples

Running commands with variable interpolation:

use xshell::{cmd, Shell};

let sh = Shell::new()?;

let name = "world";
let output = cmd!(sh, "echo hello {name}").read()?;
assert!(output.contains("hello world"));

Reading files relative to the shell’s working directory:

use xshell::Shell;
use std::path::PathBuf;

let sh = Shell::new()?;

// Read a file relative to cwd
let cargo_toml = sh.read_file("Cargo.toml")?;
assert!(cargo_toml.contains("[package]"));

Macros§

cmd
Constructs a Cmd from the given string.

Structs§

Cmd
A builder object for constructing a subprocess.
Error
An error returned by an xshell operation.
PushDir
RAII guard returned from Shell::push_dir.
PushEnv
RAII guard returned from Shell::push_env.
Shell
A Shell is the main API entry point.
TempDir
A temporary directory.

Type Aliases§

Result
Result from std, with the error type defaulting to xshell’s Error.