View source code
Display the source code in std/process.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.process.environment.get
Retrieves the value of the environment variable with the given name
,
or a default value if the variable doesn't exist.
static string get
(
scope const(char)[] name,
string defaultValue = null
) @safe;
Unlike environment
, 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 | Description |
---|---|
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
null
if the environment doesn't exist.
Throws
UTFException
if the variable contains invalid UTF-16
characters (Windows only).
Authors
Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.