Module Os.Env

Environment variables.

Variables

type var_name = string

The type for environment variable names.

val find : empty_is_none:bool -> var_name -> string option

find ~empty_is_none name is the value of the environment variable name in the current process environment, if defined. If empty_is_none is true, None is returned if the variable value is the empty string.

val find' : empty_is_none:bool -> (var_name -> ('a, string) Stdlib.result) -> var_name -> ('a option, string) Stdlib.result

find' ~empty_is_none parse name is like find but the value is parsed with parse. If the latter errors with Error e, Error (Fmt.str "%s env: %s" name e) is returned.

Process environement

type t = string String.Map.t

The type for process environments.

val empty : t
val override : t -> by:t -> t

override env ~by:o overrides the definitions in env by o.

val add : var_name -> string -> t -> t
val remove : var_name -> t -> t
val mem : var_name -> t -> bool
val current : unit -> (t, string) Stdlib.result

current () is the current process environment.

val pp : t Fmt.t

pp formats environments for inspection.

Process environments as assignments

type assignments = string list

The type for environments as lists of strings of the form "var=value".

val current_assignments : unit -> (assignments, string) Stdlib.result

current_assignments () is the current process environment as assignments.

val of_assignments : ?init:t -> string list -> (t, string) Stdlib.result

of_assignments ~init ss folds over strings in ss, cuts them at the leftmost '=' character and adds the resulting pair to init (defaults to empty). If the same variable is bound more than once, the last one takes over.

val to_assignments : t -> assignments

to_assignments env is env's bindings as assignments.

val pp_assignments : assignments Fmt.t

pp formats assignments for inspection.