2022-02-14 02:22:51 +00:00
|
|
|
---
|
|
|
|
title: with-env
|
|
|
|
layout: command
|
2022-03-04 12:10:09 +00:00
|
|
|
version: 0.59.1
|
2022-02-14 02:22:51 +00:00
|
|
|
---
|
|
|
|
|
2021-05-30 00:57:04 +00:00
|
|
|
Runs a block with an environment variable set.
|
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
## Signature
|
|
|
|
|
|
|
|
```> with-env (variable) (block)```
|
2021-05-30 00:57:04 +00:00
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
- `variable`: the environment variable to temporarily set
|
|
|
|
- `block`: the block to run once the variable is set
|
2021-05-30 00:57:04 +00:00
|
|
|
|
|
|
|
## Examples
|
2022-02-14 02:22:51 +00:00
|
|
|
|
|
|
|
Set the MYENV environment variable
|
2021-05-30 00:57:04 +00:00
|
|
|
```shell
|
2022-02-14 02:22:51 +00:00
|
|
|
> with-env [MYENV "my env value"] { $env.MYENV }
|
|
|
|
```
|
2021-05-30 00:57:04 +00:00
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
Set by primitive value list
|
2021-05-30 00:57:04 +00:00
|
|
|
```shell
|
2022-02-14 02:22:51 +00:00
|
|
|
> with-env [X Y W Z] { $env.X }
|
|
|
|
```
|
2021-05-30 00:57:04 +00:00
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
Set by single row table
|
2021-05-30 00:57:04 +00:00
|
|
|
```shell
|
2022-02-14 02:22:51 +00:00
|
|
|
> with-env [[X W]; [Y Z]] { $env.W }
|
|
|
|
```
|
2021-05-30 00:57:04 +00:00
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
Set by row(e.g. `open x.json` or `from json`)
|
2021-05-30 00:57:04 +00:00
|
|
|
```shell
|
2022-02-20 01:13:33 +00:00
|
|
|
> echo '{"X":"Y","W":"Z"}'|from json|with-env $in { echo $env.X $env.W }
|
2022-02-14 02:22:51 +00:00
|
|
|
```
|