W3cubDocs

/Nushell

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:

input output
any any

Examples

Set the MYENV environment variable

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

Set by primitive value list

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

Set by single row table

>with-env [[XW]; [YZ]] { $env.W }
Z

Set by key-value record

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

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/with-env.html