bash:
if [ ! -f .env ]; then
echo "ERR: .env file not found. Please create one, details: https://devcenter.heroku.com/articles/heroku-local#set-up-your-local-environment-variables"
exit 1
fi
win:
if not exist .env (
echo ERR: .env file not found. Please create one, details: https://devcenter.heroku.com/articles/heroku-local#set-up-your-local-environment-variables
exit /B 1
)
bash:
AWS_REGION=${AWS_REGION:=us-east-1}
AWS_PROFILE=${AWS_PROFILE:=nonprod}
bash:
MONGODB_URI=${MONGODB_URI:?"ERR: required var is empty"}
ARG_1=${1:?"ERR: first argument must be defined"}
win:
if [%MONGODB_URI%] == [] (
echo MONGODB_URI: ERR: required var is empty
exit /B 1
)
bash:
SOURCE=relative/path/to/dir
SOURCE=$(cd $SOURCE && pwd)
Given variables defined in the .env
file like:
MONGODB_URI=mongodb://user:pass@host:port/db
FOO=BAR
We can assign (evaluate) those vars and use them as a standard script vars
bash:
source .env
echo ${MONGODB_URI}
win:
for /F "tokens=*" %%A in (.env) do SET %%A
echo %MONGODB_URI%