Function in env compiler

var

fn var(string name) -> Result<string, EnvError>
Import
use env::{var};
Source: compiler/src/builtin_docs/env.hy

Returns the value of the environment variable name.

Returns Err(EnvError::NotFound) when it is not set and Err(EnvError::Other) when its value is not valid UTF-8. Needs --allow-env.

Parameters#

NameType
namestring

Returns#

Result<string, EnvError>

Examples#

use env::{var, set_var};
use tests::assert;
let _ = set_var("COIL_DOC_GREETING", "hello");
let v = match var("COIL_DOC_GREETING") {
    Result::Ok(s) => s,
    Result::Err(_) => "",
};
assert!(v == "hello");

See also#

  • args: Returns the program’s command-line arguments, starting with the program name.
  • set_var: Sets the environment variable name to value for this process.
  • remove_var: Removes the environment variable name from this process.
  • cwd: Returns the current working directory as an absolute path.
  • set_cwd: Changes the current working directory of the whole process.
  • exit: Ends the process at once with exit status code.
  • exec: Runs program with the arguments argv and waits for it to finish.
↑ ↓ navigate ↵ open