null if the environment doesn't exist.
environment.get
string get(scope const(char)[] name, string defaultValue = null) @safeRetrieves the value of the environment variable with the given name, or a default value if the variable doesn't exist.
Unlike environment.opIndex, this function never throws on Posix.
auto sh = environment.get("SHELL", "/bin/sh");This function is also useful in checking for the existence of an environment variable.
auto myVar = environment.get("MYVAR");
if (myVar is null)
{
// Environment variable doesn't exist.
// Note that we have to use 'is' for the comparison, since
// myVar == null is also true if the variable exists but is
// empty.
}Parameters
name | name of the environment variable to retrieve |
defaultValue | default value to return if the environment variable doesn't exist. |
Returns
the value of the environment variable if found, otherwise
Throws
UTFException if the variable contains invalid UTF-16
characters (Windows only).