with-env for env

Runs a block with an environment variable set.

Signature

> with-env {flags} (variable) (block)

Parameters

  • variable: The environment variable to temporarily set.
  • block: The block to run once the variable is set.

Input/output types:

inputoutput
anyany

Examples

Set the MYENV environment variable

> with-env [MYENV "my env value"] { $env.MYENV }
my env value

Set by primitive value list

> with-env [X Y W Z] { $env.X }
Y

Set by single row table

> with-env [[X W]; [Y Z]] { $env.W }
Z

Set by key-value record

> with-env {X: "Y", W: "Z"} { [$env.X $env.W] }
╭───┬───╮
 0  Y 
 1  Z 
╰───┴───╯