Function in env compiler

set_var

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

Sets the environment variable name to value for this process.

Programs started later with exec inherit it. A name or value with a NUL byte is Err(EnvError::InvalidInput). Needs --allow-env.

Parameters#

NameType
namestring
valuestring

Returns#

Result<unit, EnvError>

Examples#

use env::{set_var, var, remove_var};
use tests::assert;
assert!(match set_var("COIL_DOC_MODE", "test") { Result::Ok(_) => true, Result::Err(_) => false });
assert!(match var("COIL_DOC_MODE") { Result::Ok(s) => s == "test", Result::Err(_) => false });
let _ = remove_var("COIL_DOC_MODE");

See also#

  • env::exec
  • args: Returns the program’s command-line arguments, starting with the program name.
  • var: Returns the value of the environment variable name.
  • 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.
↑ ↓ navigate ↵ open