pub struct Bash { /* private fields */ }
Expand description
Execute an arbitrary bash script.
WARNING: this opens up the possibility of dependency injection attacks, so should only be used when the command is trusted. If compiled usage is all that’s needed, use something like rust_cmd_lib instead, which only provides a macro literal interface. https://github.com/rust-shell-script/rust_cmd_lib
This is a pure rust implementation and doesn’t rely on bash being available to make it compatible with windows. Given that, it only implements a subset of bash features, and is not intended to be a full bash implementation.
Purposeful deviations from bash:
- set -e is enabled by default, each cmd line will stop if it fails
Assume everything is unimplemented unless stated below:
&&
and||
or!
exit code negation|
pipe~
home dirfoo=bar
param setting$foo
param substitution$(echo foo)
command substitution'
quotes"
double quotes\
escaping(...)
simple compound commands e.g. (echo foo && echo bar)- Basic file/stderr/stdout redirection
This should theoretically work with multi line full bash scripts but only tested with single line commands.
Implementations§
source§impl Bash
impl Bash
sourcepub fn cmd(self, cmd: impl Into<String>) -> Self
pub fn cmd(self, cmd: impl Into<String>) -> Self
Add a new piece of logic to the bash script. E.g. a line of bash.
Multiple commands added to a Bash
instance will be treated as newline separated.
sourcepub fn chdir(self, root_dir: &Path) -> Self
pub fn chdir(self, root_dir: &Path) -> Self
Set the root directory to run the commands in.
By default, the current process’s root directory is used.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bash
impl RefUnwindSafe for Bash
impl Send for Bash
impl Sync for Bash
impl Unpin for Bash
impl UnwindSafe for Bash
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request