Expand description
Wrapper around std::process::Command which make the use of Rust for shell scripting more appealing.
§Simple example
#[macro_use]
extern crate shells;
fn main() {
let (code, stdout, stderr) = sh!("echo '{} + {}' | cat", 1, 3);
assert_eq!(code, 0);
assert_eq!(&stdout[..], "1 + 3\n");
assert_eq!(&stderr[..], "");
// Using the new `wrap_*` macros.
assert_eq!(wrap_sh!("echo '{} + {}' | cat", 1, 3).unwrap(), "1 + 3\n");
}
A mnemotechnic to remember the ordering of the elements in the resulting tuple is the positions of stdout and stderr, they correspond to the standard streams numbers: 1 and 2 respectively.
The implementation for all the different shells is the same: the arguments of the macro is
passed directly to format!
and the resulting string is passed to the shell using its ‘-c’
command line option. Thus you can use sh!
and friends the same way you would use format!
or
println!
.
Macros§
- ash
- Macro to execute the given command using the Almquist Shell.
- bash
- Macro to execute the given command using the Bourne Again Shell.
- csh
- Macro to execute the given command using the C Shell.
- dash
- Macro to execute the given command using the Debian Almquist Shell.
- fish
- Macro to execute the given command using the Fish Shell.
- ksh
- Macro to execute the given command using the Korn Shell.
- mksh
- Macro to execute the given command using the MirBSD Korn Shell.
- sh
- Macro to execute the given command using the Posix Shell.
- tcsh
- Macro to execute the given command using the TENEX C Shell.
- wrap_
ash - Macro to execute the given command using the Almquist Shell and wraping the resulting tuple into a Result.
- wrap_
bash - Macro to execute the given command using the Bourne Again Shell and wraping the resulting tuple into a Result.
- wrap_
csh - Macro to execute the given command using the C Shell and wraping the resulting tuple into a Result.
- wrap_
dash - Macro to execute the given command using the Debian Almquist Shell and wraping the resulting tuple into a Result.
- wrap_
fish - Macro to execute the given command using the Fish Shell and wraping the resulting tuple into a Result.
- wrap_
ksh - Macro to execute the given command using the Korn Shell and wraping the resulting tuple into a Result.
- wrap_
mksh - Macro to execute the given command using the MirBSD Korn Shell and wraping the resulting tuple into a Result.
- wrap_sh
- Macro to execute the given command using the Posix Shell and wraping the resulting tuple into a Result.
- wrap_
tcsh - Macro to execute the given command using the TENEX C Shell and wraping the resulting tuple into a Result.
- wrap_
zsh - Macro to execute the given command using the Z Shell and wraping the resulting tuple into a Result.
- zsh
- Macro to execute the given command using the Z Shell.
Structs§
- Error
- Struct holding the resulting environment after executing a failed command with the
wrap_*
family of macros. It implements the Error trait and its implementation of the Display trait is identical to the implementation of the Display trait of itsstderr
field.
Type Aliases§
- Result
- Type returned by the
wrap_*
family of macros. Will either beOk(stdout)
or an error containing code, stdout and stderr resulting from executing the command.