theskumar / theskumar/python-dotenv

Unable to escape posix expansion

Offen
#422 2 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@theskumar arbeitet bereits daran.

Seit 08.4.2025.

Vorherrschende Sprache
Python
Sterne
8.9k
Forks
581
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

What

Unable to elegantly escape the $ in ${VARIABLE} expansion.

Scenario

.env

VAR=${VARIABLE}

script.py

import os
import dotenv

if dotenv.find_dotenv():
    dotenv.load_dotenv(interpolate=False)

print(f"VAR={os.getenv('VAR')}"

I do not see the interpolate kwarg in the documentation, however looking at the stub: https://github.com/theskumar/python-dotenv/blob/914c68ef0e4c2c085d2753f5cbbf304852f37850/src/dotenv/main.py#L307-L330

*Edit: and the pypi documentation:

image

Expected Behavior

output

>> VAR='${VARIABLE}'

Actual Behavior

output

>> VAR=''

Workaround

My current workaround is to provide the desired string as a default value for variable expansion.

.env

VAR=${_:-${VARIABLE}]

output

>> VAR='${VARIABLE}'

System

Host: Windows 11
Python: 3.10 w/ Poetry environment

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.