.env File Syntax Reference

.env variable syntax, quoting rules, comment handling and shell expansion notes.

Reference and live linter for .env file syntax: variable assignment, single and double quoting, comments, multiline values, the export prefix and $VAR interpolation, with per-line validation.

Do .env values need quotes?

Only when they contain spaces, special characters or you want to control interpolation. Unquoted values run to the end of the line (or an inline comment) with surrounding whitespace trimmed. Double quotes preserve spaces and allow escape sequences and $VAR interpolation; single quotes are fully literal.

The .env file format

A .env file stores configuration as one KEY=value assignment per line, loaded into a process’s environment at startup. The format looks trivial, but quoting, comments and interpolation differ subtly between loaders. This reference documents the rules and includes a live linter that classifies every line you paste.

How it works

Each non-blank, non-comment line is split at the first = into a key and a value. The key should be UPPER_SNAKE_CASE and may not start with a digit:

# a comment line
API_KEY="sk_live_123"      # double quotes preserve and can interpolate
SECRET='raw$value'          # single quotes are fully literal
DB_URL=$HOST/db             # $VAR expands in many loaders
export PORT=3000            # export prefix is stripped by the loader
EMPTY=                      # assigns an empty string

The linter applies exactly this logic: blank and # lines are ignored, a valid key/value reports whether the value is quoted, empty or unquoted, and a line with no = (and not a comment) is flagged as an error.

Tips and notes

  • Single-quote any secret containing $ so it is not treated as interpolation.
  • Behaviour varies across Node dotenv, python-dotenv and docker-compose — test in your loader.
  • Never commit a real .env; ship a .env.example with placeholder values instead.
  • Keep keys UPPER_SNAKE_CASE and avoid spaces around = for the widest compatibility.