Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Place this script into your script folder and use like this:
- #
- # ./script/wrap-env.sh .env $(npm bin grunt)/grunt serve
- #
- # Your .env file must have exports in it, not just a list of variable like Docker env files work
- #
- usage="$(basename "$0") [-h] .env_file command [arg ...]
- where:
- first argument must be env variable file
- second argument must be a command you want to run, for example \`grunt\`
- optionally followed by the arguments to the command"
- while getopts ':h' option; do
- case "$option" in
- h) echo "$usage"
- exit
- ;;
- \?) printf "illegal option: -%s\n" "$OPTARG" >&2
- echo "$usage" >&2
- exit 1
- ;;
- esac
- done
- shift $((OPTIND - 1))
- if [ "$#" -le 1 ]; then
- printf "Must provide at least 2 arguments.\n" >&2
- printf "\n$usage";
- exit 1
- fi
- if ! [ -f "$1" ]; then
- printf "Environment file $1 does not exist.\n" >&2
- printf "\n$usage";
- exit 1
- fi
- source $1;
- shift;
- eval "$@";
Add Comment
Please, Sign In to add comment