Functions

getEnv
I

Returns the environment variable value associated with the provided name.

getUserHome
I

Returns the current user's home directory path.

getUsername
I

Returns the current user's name.

listEnv
I

Returns a map of environment variables.

setEnv
I

Sets the value of the environment variable named by the key.

unsetEnv
I

Removes a single environment variable from the system if it exists.

getEnv

function getEnv(string name) returns string
Isolated Function

Returns the environment variable value associated with the provided name.

1string port = os:getEnv("HTTP_PORT");

Parameters

  • name string
  • Name of the environment variable

Return Type

(string)

Environment variable value if it exists or else, an empty string

getUserHome

function getUserHome() returns string
Isolated Function

Returns the current user's home directory path.

1string userHome = os:getUserHome();

Return Type

(string)

Current user's home directory if it can be determined or else, an empty string

getUsername

function getUsername() returns string
Isolated Function

Returns the current user's name.

1string username = os:getUsername();

Return Type

(string)

Current user's name if it can be determined or else, an empty string

listEnv

function listEnv() returns map<string>
Isolated Function

Returns a map of environment variables.

1map<string> envs = os:listEnv();

Return Type

(map<string>)

Map of environment variables

setEnv

function setEnv(string key, string value) returns Error?
Isolated Function

Sets the value of the environment variable named by the key. Note that the parameter key cannot be an empty string or "==" sign.

1os:Error? err = os:setEnv("BALCONFIGFILE", "/path/to/Config.toml");

Parameters

  • key string
  • Key of the environment variable

  • value string
  • Value of the environment variable

Return Type

(Error?)

An os:Error if setting the environment variable fails, () otherwise

unsetEnv

function unsetEnv(string key) returns Error?
Isolated Function

Removes a single environment variable from the system if it exists. Note that the parameter key cannot be an empty string.

1os:Error? err = os:unsetEnv("BALCONFIGFILE");

Parameters

  • key string
  • Key of the environment variable

Return Type

(Error?)

An os:Error if unsetting the environment variable fails, () otherwise