Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load your database environment variables in the terminal session
#/!bin/bash
# 1) Change the variables to your desired environment
# 2) Use the . ./load_env.sh dev to run the script
# . load_env.sh dev ==> load dev environment variables
# . load_env.sh staging ==> load staging environment variables
# . load_env.sh production ==> load production environment variables
echo "Loading your database environment variables to your shell session..."
if [[ "${1}" == "dev" ]]; then
echo -e "Development Env"
DB_HOST_DEV="<Development database>"
export DB_PORT_DEV="<Development database port>"
export DB_USER_DEV="<Development database user>"
fi
if [[ "${1}" == "staging" ]]; then
echo "Staging Env"
export DB_HOST_STAGING="<Staging database host>"
export DB_PORT_STAGING="<Staging database port>"
export DB_USER_STAGING="<Staging database user>"
fi
if [[ "${1}" == "prod" ]]; then
echo -e "Production Env"
export DB_HOST_PROD="<Production database host>"
export DB_NAME_PROD="<Production database name>"
export DB_PORT_PROD="<Production database port>"
export DB_USER_PROD="<Production database user>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment