3.5. Environment Functions

3.5.1. getenv()

Synopsis

Retrieves the environment variable passed as an argument.

Prototype

*string getenv(string) (CONST)

nothing getenv() (RT_NOOP)

Example
my *string $v = getenv("PATH");

Table 3.99. Arguments and Return Values for getenv()

Argument Type

Return Type

Description

string

*string

The contents of the environment variable are returned as a string, if the environment variable exists, otherwise no value is returned.


This function does not throw any exceptions.

3.5.2. setenv()

Synopsis

Sets an environment variable to a value.

To unset or clear an environment variable, see unsetenv().

Prototype

int setenv(string $var, softstring $value)

nothing setenv() (RT_NOOP)

Example
setenv("PATH", "/bin:/usr/bin");

Table 3.100. Arguments and Return Values for setenv()

Argument Type

Return Type

Description

string $var, softstring $value

int

Sets the environment variable to a string value (the value is converted to a string if necessary).


This function does not throw any exceptions.

3.5.3. unsetenv()

Synopsis

Unsets an environment variable.

To set an environment variable, see setenv().

Prototype

int unsetenv(string)

nothing unsetenv() (RT_NOOP)

Example
unsetenv("PATH");

Table 3.101. Arguments and Return Values for unsetenv()

Argument Type

Return Type

Description

string

int

Unsets the environment variable given by the string passed.


This function does not throw any exceptions.

Note

This function is only supported on systems where the C library support for unsetenv() is present.