Last active
October 3, 2024 15:23
-
-
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 `=`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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