Skip to content

Instantly share code, notes, and snippets.

@unlight
Created May 17, 2025 13:42
Show Gist options
  • Save unlight/7a3c3ef32efedc940992103de1091526 to your computer and use it in GitHub Desktop.
Save unlight/7a3c3ef32efedc940992103de1091526 to your computer and use it in GitHub Desktop.
var_loadenv.cmd
@echo off
if not "x%~1"=="x/?" goto :main
echo =============================================
echo Load variables from env file.
echo ---------------------------------------------
echo usage:
echo var_loadenv [option] env-file
echo ex:
echo type some.txt -^> KEY=VALUE
echo var_loadenv some.txt
echo echo %%KEY%% ^-> VALUE
echo options:
echo\ /?: show this usage.
echo args:
echo env-file: environment file path
echo =============================================
exit /b 1
:main
if "x%~1"=="x" exit /b
for /f "eol=# tokens=1,* delims==" %%i in ( %~f1 ) do (
if not "x%%i"=="x" (
set "%%i=%%j"
echo "%%i=%%j"
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment