JustBash.Interpreter.Executor (JustBash v0.4.0)

View Source

Executes parsed bash AST nodes.

This is the main entry point for script execution. Complex functionality is delegated to submodules:

  • Executor.Conditional - [[ ]] and if/case evaluation
  • Executor.Loop - for/while/until loops
  • Executor.Redirection - File redirections (>, >>, <, etc.)

Summary

Functions

Execute a pipeline (commands connected by |).

Execute a parsed script AST. Returns {result, updated_bash}.

Execute a statement (one or more pipelines with && or ||).

Build the shell-shaped result for an exception that escaped containment.

Types

result()

@type result() :: %{
  :stdout => String.t(),
  :stderr => String.t(),
  :exit_code => non_neg_integer(),
  optional(:env) => map()
}

Functions

execute_command(bash, command, stdin \\ "")

@spec execute_command(JustBash.t(), JustBash.AST.command(), String.t()) ::
  {result(), JustBash.t()}

Execute a single command.

execute_pipeline(bash, pipeline)

@spec execute_pipeline(JustBash.t(), JustBash.AST.Pipeline.t()) ::
  {result(), JustBash.t()}

Execute a pipeline (commands connected by |).

execute_script(bash, script)

@spec execute_script(JustBash.t(), JustBash.AST.Script.t()) ::
  {result(), JustBash.t()}

Execute a parsed script AST. Returns {result, updated_bash}.

execute_statement(bash, stmt)

@spec execute_statement(
  JustBash.t(),
  JustBash.AST.Statement.t() | JustBash.AST.Group.t()
) ::
  {result(), JustBash.t()}

Execute a statement (one or more pipelines with && or ||).

internal_error(bash, detail)

@spec internal_error(JustBash.t(), String.t()) :: result()

Build the shell-shaped result for an exception that escaped containment.

Public so JustBash.exec/2's outer net reports the same way the statement loop does. Exception.message/1 is unbounded from the sandbox's point of view — inspect/1 alone allows 4096 bytes per binary and 50 collection elements — so a MatchError or KeyError carrying interpreter or filesystem state could inline sandbox file contents into a stderr the host asked to be capped. The detail is truncated to fit :max_output_bytes, or 512 bytes, whichever is smaller.