Bash variable with attributes and value. Supports scalar values, indexed arrays, and associative arrays.
Working with Sessions
You can retrieve variables directly from a session:
Variable.get(session, "myvar") # Get scalar variable
Variable.get(session, "myarray", 0) # Get array element at index 0
Variable.get(session, "myassoc", "key") # Get associative array elementOr work with Variable structs directly:
var = Variable.new("hello")
Variable.get(var, nil) # => "hello"
Summary
Functions
Get all keys for ${!arr[@]} expansion
Get all values for ${arr[@]} expansion
Returns true if the variable is an array (indexed or associative).
Returns true if the variable is an associative array.
Get length for ${#arr[@]} or ${#var}
Returns true if the variable is a nameref.
Get the nameref target variable name, or nil if not a nameref.
Create scalar variable
Create associative array
Create indexed array
Create a nameref variable that references another variable by name
Returns true if the variable is marked readonly.
Set value at index, returns new Variable
Types
@type array_type() :: :indexed | :associative | nil
@type attributes() :: %{ readonly: boolean(), export: boolean(), integer: boolean(), array_type: array_type(), nameref: String.t() | nil }
@type t() :: %Bash.Variable{attributes: attributes(), value: value()}
Functions
Get all keys for ${!arr[@]} expansion
Get all values for ${arr[@]} expansion
Returns true if the variable is an array (indexed or associative).
Returns true if the variable is an associative array.
Get length for ${#arr[@]} or ${#var}
Returns true if the variable is a nameref.
Get the nameref target variable name, or nil if not a nameref.
Create scalar variable
Create associative array
Create indexed array
Create a nameref variable that references another variable by name
Returns true if the variable is marked readonly.
Set value at index, returns new Variable