Bash.AST.If (Bash v0.3.0)

Copy Markdown View Source

Conditional statement: if/elif/else/fi.

Examples

# if [ -f file ]; then echo exists; fi
%If{
  condition: %Command{name: "test", args: ["-f", "file"]},
  body: [%Command{name: "echo", args: ["exists"]}],
  elif_clauses: [],
  else_body: nil
}

# if cmd1; then body1; elif cmd2; then body2; else body3; fi
%If{
  condition: %Command{name: "cmd1", ...},
  body: [...],
  elif_clauses: [
    {%Command{name: "cmd2", ...}, [...]}
  ],
  else_body: [...]
}

Summary

Types

t()

@type t() :: %Bash.AST.If{
  body: [Bash.Statement.t()],
  condition: Bash.Statement.t(),
  elif_clauses: [{Bash.Statement.t(), [Bash.Statement.t()]}],
  else_body: [Bash.Statement.t()] | nil,
  executed_branch: :then | :elif | :else | nil,
  exit_code: 0..255 | nil,
  meta: Bash.AST.Meta.t(),
  state_updates: map()
}

Functions

execute(if, stdin, session_state)