# Env Var Reference Extractor

Paste a shell script, Dockerfile or config and list every environment variable it references, with line numbers, defaults and an undefined check. Runs in your browser.

## Run it

- **CLI:** `gizza tool env-var-reference-extractor '#!/bin/sh
PORT=${PORT:-8080}
curl "$API_URL/health"'`
- **Web:** https://gizza.ai/tools/env-var-reference-extractor/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/env-var-reference-extractor/tool.json

## Inputs

- `text` — Script, Dockerfile or config _(field)_
- `syntax` — Reference syntax _(field)_
- `output` — Output _(field)_
- `defined` — Variables you already provide (optional) _(field)_
- `include_defined_in_source` — Count assignments in the pasted text as definitions _(field)_
- `skip_comments` — Ignore references inside comments _(field)_
- `ignore` — Names to ignore _(field)_
- `only_undefined` — Show only undefined variables _(field)_
- `sort` — Sort order _(field)_

## Output

- Referenced variables (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `text` — Script, Dockerfile or config
- `syntax` — Reference syntax
- `output` — Output
- `defined` — Variables you already provide (optional)
- `include_defined_in_source` — Count assignments in the pasted text as definitions
- `skip_comments` — Ignore references inside comments
- `ignore` — Names to ignore
- `only_undefined` — Show only undefined variables
- `sort` — Sort order

Example: `https://gizza.ai/tools/env-var-reference-extractor/?text=%23%21%2Fbin%2Fsh%0APORT%3D%24%7BPORT%3A-8080%7D%0Acurl%20%22%24API_URL%2Fhealth%22&syntax=auto&output=names&defined=PORT%3D8080%0AAPI_URL%3Dhttps%3A%2F%2Fapi.internal&include_defined_in_source=true&skip_comments=true&ignore=PATH%2C%20HOME%2C%20LC_%2A&only_undefined=true&sort=name`

---

## About this tool

Environment-variable references hide in shell scripts, Dockerfiles, batch files, CI YAML and application code. This scanner turns a pasted file into the exact set of variables it consumes, with line numbers, default values from parameter expansions and a defined/undefined status check.

Use it before writing a `.env.example`, moving a script into CI, reviewing a Dockerfile, or auditing code that reads `process.env`, `os.environ`, `System.getenv` or similar accessors. The scanner is deterministic and local: it runs in WebAssembly in your browser and never uploads your input.

### Worked example

Paste this shell fragment and choose **Output → Aligned table**:

```sh
PORT=${PORT:-8080}
curl "$API_URL/health"
echo "$PORT" # $COMMENTED_OUT
```

With comments skipped, the result is:

```text
VARIABLE  USES  LINES  DEFAULT  STATUS
API_URL   1     2               undefined
PORT      2     1, 3   8080     defined
```

To generate a starter `.env.example`, switch **Output** to `.env.example template`; the default from `${PORT:-8080}` is carried into the generated value.

## Limits and edge cases

- This is a reference scanner, not a full shell parser. Single-quoted strings and here-doc bodies are still scanned.
- Positional/special shell parameters such as `$1`, `$@`, `$?`, `$$` and `$#` are intentionally ignored.
- `\$VAR`, `$$` and batch `%%` escapes are skipped.
- Dockerfile `ENV` and `ARG`, shell assignments and Windows `set`/`setx` can count as definitions when that checkbox is enabled.
- A run is capped at 20,000 references; split extremely large repositories into files or folders.

## FAQ

<details>
<summary>Does this read my actual environment variables?</summary>

No. It scans only the text you paste and the optional “variables you already provide” list. It does not read your machine's environment, shell profile or secrets.

</details>

<details>
<summary>Why does it report variables inside single quotes or here-docs?</summary>

The tool is intentionally a deterministic text scanner rather than a full shell interpreter. It catches references in mixed config/code snippets, but that means some shell-only quoting rules are not modelled. Use the line numbers to review any borderline hit.

</details>

<details>
<summary>How do I get only the variables my deployment still needs?</summary>

Paste your script or config, paste your known `.env` values into “Variables you already provide”, and enable “Show only undefined variables”. The output then lists only variables not defined in the pasted file or your provided list.

</details>

<details>
<summary>Can it scan Dockerfiles and Windows batch files?</summary>

Yes. Use Auto-detect for most inputs, or set the syntax explicitly to Dockerfile or Windows batch. Dockerfile `ENV` and `ARG` lines and Windows `set`/`setx` assignments can count as definitions.

</details>

## Related tools

- [Lint Bash and sh Scripts](https://gizza.ai/tools/shell-script-linter/): Paste a bash, sh, dash or zsh script and catch common shell pitfalls: unquoted variables, missing strict mode, useless cat, risky rm -rf and subshell scope traps.
- [Extract Action Items from Meeting Notes](https://gizza.ai/tools/action-item-extractor/): Extract action items, owners, and decisions from meeting notes or daily notes with deterministic rules. Markdown checklist or JSON, private in-browser.
- [Add Line Numbers](https://gizza.ai/tools/add-line-numbers/): Add line numbers to every line of text online, like nl or cat -n — custom start, step, separator, and alignment. Free and private, runs in your browser.
- [ANSI Log Renderer](https://gizza.ai/tools/ansi-log-renderer/): Paste ANSI-colored terminal output or CI logs and render them as HTML, or strip escape codes to plain text. Handles 16-color, 256-color, and truecolor SGR codes.
- [API response diff](https://gizza.ai/tools/api-response-diff/): Compare two JSON API responses and see only the meaningful changes: ignore request ids, timestamps and UUIDs, match arrays by key or as sets, export a JSON Patch.
