Guest User

Untitled

a guest
Jan 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Place this script into your script folder and use like this:
  4. #
  5. # ./script/wrap-env.sh .env $(npm bin grunt)/grunt serve
  6. #
  7. # Your .env file must have exports in it, not just a list of variable like Docker env files work
  8. #
  9. usage="$(basename "$0") [-h] .env_file command [arg ...]
  10.  
  11. where:
  12. first argument must be env variable file
  13. second argument must be a command you want to run, for example \`grunt\`
  14. optionally followed by the arguments to the command"
  15.  
  16. while getopts ':h' option; do
  17. case "$option" in
  18. h) echo "$usage"
  19. exit
  20. ;;
  21. \?) printf "illegal option: -%s\n" "$OPTARG" >&2
  22. echo "$usage" >&2
  23. exit 1
  24. ;;
  25. esac
  26. done
  27. shift $((OPTIND - 1))
  28.  
  29. if [ "$#" -le 1 ]; then
  30. printf "Must provide at least 2 arguments.\n" >&2
  31. printf "\n$usage";
  32. exit 1
  33. fi
  34.  
  35. if ! [ -f "$1" ]; then
  36. printf "Environment file $1 does not exist.\n" >&2
  37. printf "\n$usage";
  38. exit 1
  39. fi
  40.  
  41. source $1;
  42.  
  43. shift;
  44.  
  45. eval "$@";
Add Comment
Please, Sign In to add comment