Last active
September 9, 2022 23:08
-
-
Save NorikDavtian/34d970b50b8c60d383d24b75ea2963f6 to your computer and use it in GitHub Desktop.
load variables from the .env file to the terminal environment.
This file contains 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
#!/bin/sh | |
# example: ./scripts/envify.sh .env.dev | |
envify() { | |
ENV_FILE="$(pwd)/.env" | |
if [ -n "$1" ]; then | |
echo "FILE: $1" | |
ENV_FILE="$(pwd)/${1}" | |
fi | |
if [ -f "$ENV_FILE" ]; then | |
echo "Loading ENV vars from $ENV_FILE" | |
else | |
echo "FILE: $1 NOT FOUND" | |
fi | |
set -a | |
[ -f "$ENV_FILE" ] && . "$ENV_FILE" | |
set +a | |
} | |
[ $# = 0 ] && echo "Will load .env file" && envify | |
[ $# != 0 ] && echo "Will load $* file" && envify "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment