Skip to content

Instantly share code, notes, and snippets.

@zvodd
Last active October 3, 2024 15:23
Show Gist options
  • Save zvodd/215575b3a0a8f07aaf5a5f5c3cfb8b97 to your computer and use it in GitHub Desktop.
Save zvodd/215575b3a0a8f07aaf5a5f5c3cfb8b97 to your computer and use it in GitHub Desktop.
load a dotenv file in windows cmd line - doesn't support values containing `=`
@echo off
if "%~1"=="" (
set "ENV_FILE=%CD%\.env"
) else (
set "ENV_FILE=%~1"
)
if not exist "%ENV_FILE%" (
echo Error: %ENV_FILE% file not found
exit /b 1
)
for /f "delims=" %%L in (%ENV_FILE%) do (
:: Split the line using '=' as the delimiter
for /f "tokens=1,2 delims==" %%A in ("%%L") do (
:: Echo the results
set "%%A=%%B"
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment