File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # Load variables from the .env file into the current shell.
4+ # NOTE: This script must be *sourced*, not executed, e.g.:
5+ # source load-env.sh
6+ # or
7+ # . ./load-env.sh
8+
9+ # If this script is run directly (./load-env.sh), print a warning because
10+ # environment changes will not persist in the parent shell.
11+ if [[ " ${BASH_SOURCE[0]} " == " $0 " ]]; then
12+ echo " [load-env] This script must be sourced to affect the current shell:" >&2
13+ echo " source load-env.sh" >&2
14+ exit 1
15+ fi
16+
17+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
18+ ENV_FILE=" $SCRIPT_DIR /.env"
19+
20+ if [[ ! -f " $ENV_FILE " ]]; then
21+ echo " [load-env] No .env file found at: $ENV_FILE " >&2
22+ return 1
23+ fi
24+
25+ # Auto-export all variables defined while the script runs
26+ set -a
27+ source " $ENV_FILE "
28+ set +a
29+
30+ echo " [load-env] Loaded environment variables from $ENV_FILE "
You can’t perform that action at this time.
0 commit comments