Skip to content

Instantly share code, notes, and snippets.

@angryobject
Last active November 13, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angryobject/0a6e894e168dc9471b4a53f0deed3357 to your computer and use it in GitHub Desktop.
Save angryobject/0a6e894e168dc9471b4a53f0deed3357 to your computer and use it in GitHub Desktop.
Runs command with environment variables declared in a .env file
# Runs command with environment variables declared in a .env file
# Usage:
# $ envr some fancy command to run
# or with a custom .env file:
# $ envr .my.env some fancy command to run
if [[ "$1" =~ ^.*\.env$ ]]; then
ENV_FILE=$1
CMD=${@:2}
else
ENV_FILE=".env"
CMD=$@
fi
env $(cat $ENV_FILE | xargs) $CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment