## `setEnv`

### Signature

```solidity
function setEnv(string calldata key, string calldata value) external;
```

### Description

Sets an environment variable `key=value`.

### Parameters

| Parameter | Type     | Description                          |
|-----------|----------|--------------------------------------|
| `key`     | `string` | The environment variable name        |
| `value`   | `string` | The value to set                     |

### Examples

```solidity [test/SetEnv.t.sol]
string memory key = "hello";
string memory val = "world";
vm.setEnv(key, val);
```

### Gotchas

:::note
Environment variables set by a process are only accessible by itself and its child processes. Thus, calling `setEnv` will only modify environment variables of the currently running `forge` process, and won't affect the shell (`forge`'s parent process). The environment variables won't persist after the `forge` process exits.
:::

:::warning
* The environment variable key can't be empty.
* The environment variable key can't contain the equal sign `=` or the NUL character `\0`.
* The environment variable value can't contain the NUL character `\0`.
:::

### Related Cheatcodes

* [`envString`](/reference/cheatcodes/env-string) - Read environment variables as strings
* [`envOr`](/reference/cheatcodes/env-or) - Read environment variables with default values
