Quirrel4.41.0

system.getenv

Defined in module "system"
from "system" import getenv
getenv(name: string): string|null

Returns the value of the environment variable or null

Parameters

namestringname of the environment variable to read

Return value

The variable's value as a string, or null if no variable with that name is set.

Notes

A missing variable returns null rather than crashing. The C getenv call underneath can itself return a null pointer, and the binding pushes that pointer straight into sq_pushstring without an explicit null check, but sq_pushstring treats a null pointer as "push null", so the missing case is safe.

This signature is the PC one. sqstdsystem.cpp builds getenv, setenv and system only #if _TARGET_PC; on every other target (consoles, mobile) each is replaced by a stub that throws getenv() not available for this platform. Code meant to run on those targets should treat this function as absent and catch the error, or avoid it.

Example

examples/system/getenv.nut
from "system" import getenv

// a name this unlikely to be set keeps the "not found" path the same everywhere
let v = getenv("QUIRREL_REFDOC_EXAMPLE_UNSET_VAR")
println("v =", v)
println("type(v) =", type(v))
Output:
v = null
type(v) = null

See also

setenvSets the environment variable to the given value
systemmodule index