All Tools View Categories About Contact Privacy

.env to Shell Export Script Converter

Convert a .env file into a safe, sourceable shell export script — correct quoting for every value.

Runs entirely in your browser — nothing is uploaded.

About .env to Shell Export Script Converter

A .env file is data, but shells execute code — and source .env blurs that line. It works until a value contains a space, a $, a quote or a newline, and then your script breaks, your secrets get mangled or your shell runs something it should not. The reliable pattern is to convert the file into a script of properly escaped export KEY=value lines that you source consciously.

The .env to Shell Export Converter produces exactly that. Every KEY is emitted as a valid shell assignment, every value is wrapped in single quotes with embedded quotes escaped the standard POSIX way, and options let you toggle the export keyword, add a shebang, include or strip comments, and choose verbose or silent output.

The result is deterministic and reviewable — you can eyeball the whole script before sourcing it — and because comments, blank lines and quoted .env values are all handled, the script behaves identically to the variables you defined.

Features

  • Safe quoting: single quotes wrap every value; embedded quotes are POSIX-escaped.
  • export toggle: emit export KEY or bare KEY per preference.
  • Shebang: optional #!/bin/sh header so the file runs directly.
  • Verbose or silent: keep # comments or strip them for a minimal script.
  • No expansion: dollar signs and backslashes stay literal — never evaluated.
  • Special chars: spaces, ampersands, stars and newlines survive exactly.
  • Duplicate detection: repeated keys are flagged with line numbers.
  • Copy or download: clipboard or a .sh file ready to source.
  • Private: all conversion happens in your browser.

How to Use

  1. Paste your .env content into the input box, or load the sample with tricky values.
  2. Tune the options. Toggle export keyword, shebang, and comment handling.
  3. Click Convert. The shell script appears on the right.
  4. Review warnings such as duplicate keys above the output.
  5. Copy or download the .sh file, then source it: source ./env.sh.

Examples

Example 1 — Local runner. A developer converts their .env into env.sh, sources it in their terminal, and every variable they set before is exported to their node or go processes.

Example 2 — Deployment job. An SRE generates an export script from the release .env and sources it before a service start command on a minimal image.

Example 3 — Cron wrapper. A cron job sources the generated script first so background tasks get the same environment as interactive shells.

Example 4 — Sensitive credentials. A security-minded engineer uses the silent output that strips comments, keeping secrets out of visible documentation while remaining fully functional.

Example 5 — Cross-machine bootstrap. A team ships the same generated env.sh to collaborators so all machines load identical environment values without relying on a dotfile runner.

Benefits

  • Safe to source: values are never evaluated as shell code.
  • Exact values: spaces, dollars and quotes round-trip perfectly.
  • Readable: deterministic, reviewable script output.
  • Flexible: export toggle, shebang and verbosity controls.
  • Reusable: works under bash, zsh and most POSIX shells.
  • Private & free: browser-only conversion, no account.

Frequently Asked Questions

What does this tool do?
It reads a .env file of KEY=value lines and emits a shell script with lines such as export DATABASE_URL='value'. Values are safely quoted so they can be sourced by bash or zsh without breaking on spaces, special characters or embedded quotes.
Why not just source the .env directly?
Sourcing a .env runs it as shell code — dangerous with untrusted values and broken by special characters. This tool escapes every value correctly, so the result is both safe and loads cleanly with source ./env.sh.
How are quotes handled?
Every value is wrapped in single quotes. A single quote inside the value is escaped the standard shell way (close quote, backslash-quote, reopen quote), so values like it's raining are preserved exactly.
Should lines use export or plain assignments?
Both are available. With Export keyword enabled you get export KEY=value (the variable reaches child processes); without it, KEY=value just sets the variable for the current shell — useful for building a loading script.
Does it handle special characters?
Yes. Spaces, ampersands, dollar signs, backslashes, stars and newlines are all safe because single-quoted values stop shell expansion. Dollar signs are never interpreted, so secrets stay literal.
Is my data uploaded?
No. Everything runs client-side in your browser. Nothing is sent to any server, stored or logged.
Can I use the output for cron or systemd?
Yes. The generated script can be sourced in a cron wrapper or run before a service start command; Keep comments available in the .env, or a minimal silent version, depending on the verbosity toggle.