Load an .env file into the environment prior to running something which requires the environment variables:
Contents of the.envfileMY_SUPER_SECRET_TOKEN="foo"
set -a
source .env
set +aYou can now use the variables from the .env file in scripts:
$ echo $MY_SUPER_SECRET_TOKEN
fooLoad .env file from .bashrc, .zshrc, etc.
If you keep your configuration, like I do, in a public dotfiles repository, you might want to keep your
.env file secret, and make sure it is added to your .gitignore file. Then you can have it loaded
from your .bashrc or .zshrc file:
.bashrcif [ -f $HOME/.env ]; then set -a source $HOME/.env set +a else echo "Warning: $HOME/.env does not exist" fi