On this page:
String  Env  Var  Name
Bytes  Env  Var  Name
getenv
putenv
Env  Vars
Env  Vars.copy
Env  Vars.current
Env  Vars.get
Env  Vars.set
Env  Vars.names
Env  Vars.handle
Env  Vars.from_  handle
0.45+9.2.0.2

14.4 Environment Variables🔗ℹ

 import: rhombus/envvar package: rhombus-lib

annotation

envvar.StringEnvVarName

 

annotation

envvar.BytesEnvVarName

Annotations that recognize strings and bytes without null characters or = characters, which makes them suitable as environment-variable names.

function

fun envvar.getenv(

  name :: StringEnvVarName

) :: StringNoNull

 

function

fun envvar.putenv(

  name :: StringEnvVarName,

  value :: StringNoNull

) :: Boolean

Convenience functions to get and set environment variables in terms of strings.

The underlying environment-variables object works in terms of byte strings. String names and values are converted using the current locale’s default encoding, using Char"?" as the replacement character for encoding errors.

The gettenv and putenv functions use EnvVars.current to get the current environment variables, and then use EnvVars.get or EnvVars.set to get or set the byte-string encoding of name.

The putenv function returns #true for success and #false for failure, where failure is only possible when EnvVars.current returns the original EnvVars object for the process.

class

class envvar.EnvVars():

  constructor ({ name :: BytesEnvVarName: value :: BytesNoNull,

                 ... })

 

method

method (envvars :: envvar.EnvVars).copy() :: EnvVars

 

context parameter

Parameter.def envvar.EnvVars.current :: EnvVars

An EnvVars instance represents a set of environment variables. The current object installed in EnvVars.current determines the environment variables that are used for a subprocess created via rhombus/subprocess.

The initial value of EnvVars.current corresponds to the process’s environment variables. Setting an environment variable in that object adjusts the table of environment variables at the operating-system process level.

Creating a new set of environment variables via EnvVars.copy or the EnvVars allocates an object with independent state.

method

method (envvars :: envvar.EnvVars).get(

  name :: BytesEnvVarName

) :~ maybe(ImmutableBytes)

 

method

method (envvars :: envvar.EnvVars).set(

  name :: BytesEnvVarName,

  val :: maybe(BytesNoNull),

  ~fail: fail :: Function.of_arity(0) = ....

)

Gets or sets an environment variable in envvars.

If envvars is the initial value of EnvVars.current in the process, setting an environment variable adjusts the table of environment variables at the operating-system process level.

Setting an environment variable to #false removes it from the set of environment-variable names and/or unsets it at the process level.

method

method (envvars :: envvar.EnvVars).names()

  :: List.of(BytesEnvVarName && ImmutableBytes)

Returns a list of environment-variable names that are set in envvars.

property

property (envvars :: envvar.EnvVars).handle

 

function

fun envvar.EnvVars.from_handle(handle) :: EnvVars

The EnvVars.handle property accesses an environment-variables object’s underlying Racket representation. The EnvVars.from_handle function constructs a Rhombus environment-variables object from a Racket environment-variables object.