Environment Variables

Wikipedia: Environment variable
The os module provides getenv, setenv, unsetenv, and lookup_env for reading and writing the process environment.

fmt := import("fmt")
os := import("os")
fmt.println(os.getenv("HOME"))
fmt.println(os.getenv("NONEXISTENT"))
os.setenv("GREETING", "hello")
fmt.println(os.getenv("GREETING"))
val, ok := os.lookup_env("GREETING")
fmt.printf("%v %v\n", val, ok)

_, ok = os.lookup_env("MISSING")
fmt.println(ok)

os.unsetenv("GREETING")

try it

/home/tengo

hello
["hello", true] <undefined>
loading…