theskumar / theskumar/python-dotenv

Unable to escape posix expansion

Open
#422 2 comments 0 reactions 1 assignee View on GitHub

@theskumar is already working on this.

Since Apr 8, 2025.

Dominant language
Python
Stars
8.9k
Forks
581
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.