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