mirror of
https://github.com/nushell/nushell.git
synced 2024-12-02 05:13:56 +01:00
39 lines
679 B
Markdown
39 lines
679 B
Markdown
---
|
|
title: with-env
|
|
layout: command
|
|
version: 0.59.1
|
|
---
|
|
|
|
Runs a block with an environment variable set.
|
|
|
|
## Signature
|
|
|
|
```> with-env (variable) (block)```
|
|
|
|
## Parameters
|
|
|
|
- `variable`: the environment variable to temporarily set
|
|
- `block`: the block to run once the variable is set
|
|
|
|
## Examples
|
|
|
|
Set the MYENV environment variable
|
|
```shell
|
|
> with-env [MYENV "my env value"] { $env.MYENV }
|
|
```
|
|
|
|
Set by primitive value list
|
|
```shell
|
|
> with-env [X Y W Z] { $env.X }
|
|
```
|
|
|
|
Set by single row table
|
|
```shell
|
|
> with-env [[X W]; [Y Z]] { $env.W }
|
|
```
|
|
|
|
Set by row(e.g. `open x.json` or `from json`)
|
|
```shell
|
|
> echo '{"X":"Y","W":"Z"}'|from json|with-env $in { echo $env.X $env.W }
|
|
```
|