Pelago
stdSystem

std.env

Read environment variables.

import std.env
FunctionResultNotes
env.get(name)string?The value, or none when the variable is not set. A variable set to empty text is some("").
env.has(name)boolWhether it is set, even to empty text.
env.vars()[(string, string)]Every variable as a (name, value) pair.

The values are copies, so they stay valid for as long as the program runs.

On Windows, variable names are compared ignoring ASCII case, as the system does (env.get("Path") finds PATH), and the hidden entries whose names start with = (the per-drive current directories) are not listed by env.vars(). On Linux and macOS names are compared exactly.

import std.env

fn main() {
    print(env.has("PELAGO_DOCS_SURELY_NOT_SET"), env.get("PELAGO_DOCS_SURELY_NOT_SET"))
    print(env.get("PELAGO_DOCS_SURELY_NOT_SET") ?? "default")
}
false none
default

Like main(args), this works in the interpreter and on Linux (x86-64 and AArch64), Windows (x86-64 and ARM64) and macOS (AArch64).