# Systemd .env format

`systemd-env-format` · version 1.0.0 · Structured formats · free, no key needed

Format assignments into canonical systemd EnvironmentFile text, one quoting mode per value.

**Use when you need to: format a systemd environment file · write systemd EnvironmentFile text · quote a value for a systemd environment file.**

## Decide before calling

Read the [versioned contract](/v1/tools/systemd-env-format/versions/1.0.0) and the supported scope below. Reuse `systemd-env-format@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `systemd-env-format@1.0.0` for format a systemd environment file. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- format a systemd environment file
- write systemd EnvironmentFile text
- quote a value for a systemd environment file
- serialize systemd environment assignments
- canonical systemd environmentfile line
- render systemd env assignments as text
- systemd environment file from key value pairs

## Not supported

- expand specifiers while writing an EnvironmentFile
- split one formatted value into shell words
- emit shell-joined quote pieces for one value

## Behavior

- Each value has one spelling. With no CR or LF it is unquoted: every backslash is doubled, each leading or trailing space or tab is prefixed by a backslash, and a value that starts with a quote is prefixed by a backslash on that quote. Interior spaces and interior quotes stay as themselves. A single backslash is therefore written as \\.
- A value that contains CR or LF and no single quote is wrapped in single quotes and copied unchanged. If it also contains a single quote, it is wrapped in double quotes and only \ " ` and $ gain a backslash. A line break inside those quotes is a raw line break.
- Assignments are written in input order, one record per item, LF between records, and a final LF when the list is not empty. Duplicate keys are kept. Parsing the text with systemd-env-parse returns the same keys, values, and order. max_output_bytes measures that text, not the JSON envelope.

## Input

- `assignments` (array of object, required): max items 128

## Output

- `text` (string, required): Canonical EnvironmentFile text using LF line breaks.

## Limits

- max assignments: 128
- max total bytes: 4096
- max value bytes: 4096
- max key chars: 128
- max output bytes: 6000

## Example

Request input:

```json
{
  "assignments": [
    {
      "key": "PATH",
      "value": "\\"
    }
  ]
}
```

Response:

```json
{
  "result": {
    "text": "PATH=\\\\\n"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "systemd-env-format",
  "version": "1.0.0",
  "input": {
    "assignments": [
      {
        "key": "PATH",
        "value": "\\"
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/systemd-env-format/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"assignments":[{"key":"PATH","value":"\\"}]}'
```

The machine-readable contract is at [/v1/tools/systemd-env-format/versions/1.0.0](/v1/tools/systemd-env-format/versions/1.0.0).

### CLI

```sh
node cli.mjs run systemd-env-format 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Gitconfig format](/tools/gitconfig-format): Format git config sections as canonical text with escapes and subsections.
- [Systemd .env parse](/tools/systemd-env-parse): Parse a systemd EnvironmentFile into assignments, a last-wins map, and duplicate keys.
- [Systemd directive list](/tools/systemd-directive-list): List systemd unit directives as words using syntax quoting, continuation, and resets.
- [Gitconfig key list](/tools/gitconfig-key-list): List git config keys in file order with qualified names and occurrences.
- [XML exc c14n canonicalize](/tools/xml-exc-c14n-canonicalize): Exclusive XML Canonicalization 1.0 of a whole document, with an optional inclusive prefix list.
- [XML exc c14n subtree](/tools/xml-exc-c14n-subtree): Exclusive XML Canonicalization 1.0 of one selected element and its descendants.
