Skip to content

Instantly share code, notes, and snippets.

@NorikDavtian
Last active September 9, 2022 23:08
Show Gist options
  • Save NorikDavtian/34d970b50b8c60d383d24b75ea2963f6 to your computer and use it in GitHub Desktop.
Save NorikDavtian/34d970b50b8c60d383d24b75ea2963f6 to your computer and use it in GitHub Desktop.
load variables from the .env file to the terminal environment.
#!/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