Skip to content

Instantly share code, notes, and snippets.

@aljp
Last active May 24, 2016 05:25
Show Gist options
  • Save aljp/9c16e953d322fdacbb4515d711454cdc to your computer and use it in GitHub Desktop.
Save aljp/9c16e953d322fdacbb4515d711454cdc to your computer and use it in GitHub Desktop.
Given a .env file in the working directory with lines in the format ENV_NAME=ENV_VALUE, it will assign these environment variables
MY_ENV=MY_VAL
MY_ENV_2=MY_VAL_2
MY_ENV_3=MY_VAL_3
MY_ENV_WITH_EQUAL=MY_VAL=BROKEN
SETLOCAL ENABLEEXTENSIONS :: This actually prevents environment variables from being modified and you should remove this line if you mean to use it
SET me=%~n0
SET parent=%~dp0
@ECHO OFF
:: Currently has an issue where if the value has an = in it (such as our secret key!) then it only gets the value up to the first =
FOR /f "tokens=1,2 delims==" %%a IN (.env) DO (
SET "%%a=%%b"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment