#549·dotenv

Variable substitution after backslash \ character

Author: louis-lo-ribCreated Jul 17, 2026Updated Jul 17, 2026

Writing my env file for a Windows path and it surprisingly doesn't work very well

When a double-quoted value contains \\ (an escaped literal backslash) immediately followed by a variable reference ($VAR or ${VAR}), the variable is not substituted. Instead the literal text $VAR is left in the output, and the backslash is silently dropped.

.env file:

FOO=bar
RESULT="a\\\\$FOO"

Using dotenv 3.2.0, with require 'dotenv/load'

Expected: "a\\bar" (one literal backslash, then the substituted value of FOO)

Actual: "a$FOO" (backslash is gone, and $FOO is left as literal unsubstituted text)