3.5. Environment Functions

3.5.1. getenv()

Synopsis

Retrieves the environment variable passed as an argument.

Usage
getenv(variable_name)
Example
$v = getenv("PATH");

Table 3.84. Arguments and Return Values for getenv()

Argument Type

Return Type

Description

String

String

The contents of the environment variable, if the environment variable exists, otherwise returns no value.


This function does not throw any exceptions.

3.5.2. setenv()

Synopsis

Sets an environment variable to a value.

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

Table 3.85. Arguments and Return Values for setenv()

Argument Type

Return Type

Description

String, String

n/a

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.

Usage
unsetenv(key_string)
Example
unsetenv("PATH");

Table 3.86. Arguments and Return Values for unsetenv()

Argument Type

Return Type

Description

String

n/a

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.