.env file error: unterminated quoted value

In a .env file, a value that starts with a quote continues until the matching closing quote. Many dotenv libraries allow double-quoted values to span lines, so a missing quote silently absorbs the following variables into one value, or the whole rest of the file fails to parse. Your app then sees variables as unset even though they are clearly in the file. PasteKit points at the line where the unterminated quote starts.

Seen as:

  • Python-dotenv could not parse statement starting at line 1
  • bash: .env: line 1: unexpected EOF while looking for matching `"'
  • Unterminated double-quoted value for APP_NAME starting at line 1

Input

Settings

History

Load from URL

Common causes

1. A missing closing quote

The most common case: the value was edited and its closing quote deleted. Everything up to the next quote, often several lines later, becomes part of the value.

Before
APP_NAME="Invoice Service
DEBUG=false
After
APP_NAME="Invoice Service"
DEBUG=false

2. An apostrophe inside a single-quoted value

Single quotes cannot be escaped inside single-quoted values, so 'Don't stop' ends after Don. Use double quotes around text that contains apostrophes.

Before
TAGLINE='Don't stop'
After
TAGLINE="Don't stop"

3. Unescaped double quotes inside a double-quoted value

An inner " closes the value early. Escape it with a backslash, or switch to single quotes if the value has no apostrophes.

Before
GREETING="Say "hi" to Ada"
After
GREETING="Say \"hi\" to Ada"

4. A multi-line secret pasted without care

PEM keys and certificates span many lines. Keep them in double quotes with the closing quote after the END line, or put the whole key on one line with \n escapes, which every dotenv implementation understands.

Before
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBg
-----END PRIVATE KEY-----
After
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBg\n-----END PRIVATE KEY-----"

Frequently asked questions

Why are my variables undefined even though they are in the file?

An unterminated quote above them turned those lines into part of an earlier value. Check the line where the first missing variable appears and the quotes on the lines before it.

Do .env values need quotes at all?

Only when the value has leading or trailing spaces, a # that is not a comment, or line breaks. Plain values such as URLs and numbers can be written without quotes.

Is there one standard .env syntax?

No. dotenv for Node, python-dotenv, Docker Compose and shell sourcing differ in how they handle quotes, escapes and multi-line values. Simple KEY=value lines with double quotes when needed work everywhere.

Related