pub struct Shell { /* private fields */ }Expand description
A POSIX shell interpreter instance.
Each Shell maintains its own variable scope, working directory, function
definitions, and options — safe for concurrent use across threads (one Shell
per thread; Shell itself is not Sync).
§Quick start
use epsh::eval::Shell;
let mut shell = Shell::new();
let exit_code = shell.run_script("echo hello");§Builder pattern
use epsh::eval::Shell;
use std::path::PathBuf;
let mut shell = Shell::builder()
.cwd(PathBuf::from("/project"))
.errexit(true)
.build();Implementations§
Source§impl Shell
impl Shell
Sourcepub fn builder() -> ShellBuilder
pub fn builder() -> ShellBuilder
Create a ShellBuilder for configuring a new shell instance.
Sourcepub fn set_cancel_flag(&mut self, flag: Arc<AtomicBool>)
pub fn set_cancel_flag(&mut self, flag: Arc<AtomicBool>)
Set a cancellation flag. When the flag is set to true, the shell
will abort execution at the next check point with ShellError::Cancelled.
Sourcepub fn set_timeout(&mut self, duration: Duration)
pub fn set_timeout(&mut self, duration: Duration)
Set an execution timeout. The shell will abort with ShellError::TimedOut
when the deadline is exceeded, checked at the same points as cancellation.
Sourcepub fn exit_status(&self) -> ExitStatus
pub fn exit_status(&self) -> ExitStatus
Last command’s exit status ($?).
Sourcepub fn set_stdout_sink(&mut self, sink: Arc<Mutex<dyn Write + Send>>)
pub fn set_stdout_sink(&mut self, sink: Arc<Mutex<dyn Write + Send>>)
Set a stdout sink. Builtin output will be written here instead of fd 1.
Sourcepub fn set_stderr_sink(&mut self, sink: Arc<Mutex<dyn Write + Send>>)
pub fn set_stderr_sink(&mut self, sink: Arc<Mutex<dyn Write + Send>>)
Set a stderr sink. Error output will be written here instead of fd 2.
Sourcepub fn set_external_handler(&mut self, handler: ExternalHandler)
pub fn set_external_handler(&mut self, handler: ExternalHandler)
Set a callback that replaces the default external command execution.
When set, the handler is called instead of eval_external for commands
that are not builtins or functions. Redirections are already applied to
fds before the handler runs. The handler receives:
args: expanded arguments (args[0] is the command name)env: prefix assignment pairs (FOO=bar cmd→[("FOO", "bar")])
Sourcepub fn set_args_bytes(&mut self, args: &[ShellBytes])
pub fn set_args_bytes(&mut self, args: &[ShellBytes])
Set shell arguments as raw shell bytes.
Sourcepub fn resolve_path(&self, p: &str) -> PathBuf
pub fn resolve_path(&self, p: &str) -> PathBuf
Resolve a path against the shell’s working directory.
Absolute paths are returned as-is; relative paths are joined with self.cwd.
Sourcepub fn resolve_path_bytes(&self, p: &ShellBytes) -> PathBuf
pub fn resolve_path_bytes(&self, p: &ShellBytes) -> PathBuf
Resolve a path against the shell’s working directory from raw shell bytes.
Sourcepub fn run_script(&mut self, source: &str) -> i32
pub fn run_script(&mut self, source: &str) -> i32
Execute a shell script from source text.
Sourcepub fn run_program(&mut self, program: &Program) -> ExitStatus
pub fn run_program(&mut self, program: &Program) -> ExitStatus
Execute a pre-parsed program. Returns the final exit status.
This is the library-facing entry point — parse once with Parser,
then execute via run_program.
Sourcepub fn set_var(&mut self, name: &str, value: &str) -> Result<(), String>
pub fn set_var(&mut self, name: &str, value: &str) -> Result<(), String>
Set a variable. Returns error if the variable is readonly.
Sourcepub fn set_var_bytes(
&mut self,
name: &str,
value: ShellBytes,
) -> Result<(), String>
pub fn set_var_bytes( &mut self, name: &str, value: ShellBytes, ) -> Result<(), String>
Set a variable from raw shell bytes.
Sourcepub fn get_var_bytes(&self, name: &str) -> Option<&ShellBytes>
pub fn get_var_bytes(&self, name: &str) -> Option<&ShellBytes>
Get a variable’s raw bytes.
Sourcepub fn eval_command(&mut self, cmd: &Command) -> Result<ExitStatus>
pub fn eval_command(&mut self, cmd: &Command) -> Result<ExitStatus>
Evaluate a command node, returning its exit status.
Sourcepub fn command_subst(&mut self, cmd: &Command) -> Result<String>
pub fn command_subst(&mut self, cmd: &Command) -> Result<String>
Execute a command substitution and return its output.
Trait Implementations§
Source§impl ShellExpand for Shell
impl ShellExpand for Shell
fn vars(&self) -> &Variables
fn vars_mut(&mut self) -> &mut Variables
fn exit_status(&self) -> ExitStatus
fn pid(&self) -> u32
fn cwd(&self) -> &Path
Source§fn shell_flags(&self) -> String
fn shell_flags(&self) -> String
$- (e.g. “eux”).Source§fn last_bg_pid(&self) -> Option<u32>
fn last_bg_pid(&self) -> Option<u32>
$!, if any.