src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/eval/builtin_fn_env.d.elv (about)

     1  # Sets an environment variable to the given value. Calling `set-env VAR_NAME
     2  # value` is similar to `set E:VAR_NAME = value`, but allows the variable name
     3  # to be dynamic.
     4  #
     5  # Example:
     6  #
     7  # ```elvish-transcript
     8  # //unset-env X
     9  # ~> set-env X foobar
    10  # ~> put $E:X
    11  # ▶ foobar
    12  # ```
    13  #
    14  # See also [`get-env`](), [`has-env`](), and [`unset-env`]().
    15  fn set-env {|name value| }
    16  
    17  # Unset an environment variable. Calling `unset-env VAR_NAME` is similar to
    18  # `del E:VAR_NAME`, but allows the variable name to be dynamic.
    19  #
    20  # Example:
    21  #
    22  # ```elvish-transcript
    23  # //unset-env X
    24  # ~> set E:X = foo
    25  # ~> unset-env X
    26  # ~> has-env X
    27  # ▶ $false
    28  # ~> put $E:X
    29  # ▶ ''
    30  # ```
    31  #
    32  # See also [`has-env`](), [`get-env`](), and [`set-env`]().
    33  fn unset-env {|name| }
    34  
    35  # Test whether an environment variable exists. This command has no equivalent
    36  # operation using the `E:` namespace (but see https://b.elv.sh/1026).
    37  #
    38  # Examples:
    39  #
    40  # ```elvish-transcript
    41  # //set-env PATH /bin
    42  # //unset-env NO_SUCH_ENV
    43  # ~> has-env PATH
    44  # ▶ $true
    45  # ~> has-env NO_SUCH_ENV
    46  # ▶ $false
    47  # ```
    48  #
    49  # See also [`get-env`](), [`set-env`](), and [`unset-env`]().
    50  fn has-env {|name| }
    51  
    52  # Gets the value of an environment variable. Throws an exception if the
    53  # environment variable does not exist.
    54  #
    55  # Calling `get-env VAR_NAME` is similar to `put $E:VAR_NAME`, but allows the
    56  # variable name to be dynamic, and throws an exception instead of producing an
    57  # empty string for nonexistent environment variables.
    58  #
    59  # Examples:
    60  #
    61  # ```elvish-transcript
    62  # //set-env LANG zh_CN.UTF-8
    63  # //unset-env NO_SUCH_ENV
    64  # ~> get-env LANG
    65  # ▶ zh_CN.UTF-8
    66  # ~> get-env NO_SUCH_ENV
    67  # Exception: non-existent environment variable
    68  #   [tty]:1:1-19: get-env NO_SUCH_ENV
    69  # ```
    70  #
    71  # See also [`has-env`](), [`set-env`](), and [`unset-env`]().
    72  fn get-env {|name| }