Skip to content
FutureBlitz

    Install

    Import std.os.env

    std.os.env

    Env, the environment's variables, which the program starts with and passes on to what it starts: Get, Set, Unset, All, and Expand, which any thread can use, and Load, which sets those a .env file names.

    std/os/env.fb

    Types

    Env struct

    Public Struct Env

    Env's Static Methods.

    std/os/env.fb, line 19

    • Public Static Method Get(name: String): String? static method #

      The variable name's value, or Null when it isn't set. On Windows a name is the same in any case, so "Path" is "PATH".

    • @PanicsAtCaller Public Static Method Set(name: String, value: String) static method #

      Sets the variable name to value. Panics when name is empty or has an '=' or a NUL, or value has a NUL, which no variable can.

    • @PanicsAtCaller Public Static Method Unset(name: String) static method #

      Removes the variable name, when it's set. Panics when name can't be a variable's, as Set does.

    • Public Static Method All(): Map<String, String> static method #

      Every variable, by its name.

    • Public Static Method Expand(text: String): String static method #

      text with each $NAME and ${NAME} in it given its variable's value, or "" when it isn't set, and each $$ given as one '$'. A name is a letter or '', then letters, digits, and ''s, as long as it goes, and any other '$' stays as it is.

    • Public Static Method Load(path: Path, replace: Bool = False) Throws IOError, ParseError static method #

      Sets the variables the .env file at path names, each in a line of its own, as NAME=value, with "export " before it or not, and blanks around the '=' or not. A line that's blank or starts with '#' is skipped. A value in 's is as it is, and one in "s can hold \n, \r, \t, ", \, and $, and both can go on over lines; one without them ends at its line's end, or at a '#' at its start or after a blank, which starts a comment, without the blanks before it. Only a comment can follow a quoted one. A value that isn't in 's is Expanded, its $NAMEs given what's set, the lines before it included. A variable that's already set is left as it is, unless replace is True; one the file names again takes its last value. Throws an IOError when the file can't be read, and a ParseError, with its line and column, for a line that isn't one of these, a quote that isn't closed, a ${ without a name and '}', or a value with a NUL, before any variable is set.

    Report an issue with this page or with FutureBlitz on GitHub.