Module bash_builtins::variables [−][src]
Expand description
This module contains functions to get, set, or unset shell variables.
Use set and unset to modify shell variables.
Use the find functions to access the value contained in existing shell
variables. find_raw provides access to the raw pointer owned by bash,
and both find and find_as_string provides a safe interface to such
value.
Example
The following example uses the shell variable $SOMENAME_LIMIT to set the
configuration value for the builtin. If it is not present, or its value is
not a valid usize, it uses a default value
use bash_builtins::variables;
const DEFAULT_LIMIT: usize = 1024;
const LIMIT_VAR_NAME: &str = "SOMENAME_LIMIT";
fn get_limit() -> usize {
variables::find_as_string(LIMIT_VAR_NAME)
.as_ref()
.and_then(|v| v.to_str().ok())
.and_then(|v| v.parse().ok())
.unwrap_or(DEFAULT_LIMIT)
}Dynamic Variables
Dynamic variables are shell variables that use custom functions each time
they are accessed (like $SECONDS or $RANDOM).
Use bind to create a dynamic variable with any type implementing
DynamicVariable.
Structs
Raw reference to a shell variable.
Enums
Contains the value of a shell variable.
Traits
The DynamicVariable provides the implementation to create dynamic
variables.
Functions
Bind the shell variable referenced by name to an instance of
DynamicVariable.
Returns a copy of the value of the shell variable referenced by name.
Returns a string with the value of the shell variable name.
Returns a reference to the address of the shell variable referenced by
name.
Sets the value of the shell variable referenced by name.
Unset the shell variable referenced by name.