Skip to content

Instantly share code, notes, and snippets.

@kunokdev
Last active June 7, 2023 13:04
Show Gist options
  • Save kunokdev/e67888303cd8f65b3e235cba0f2cad20 to your computer and use it in GitHub Desktop.
Save kunokdev/e67888303cd8f65b3e235cba0f2cad20 to your computer and use it in GitHub Desktop.
Reads each line of .env file, uses env var value is set, otherwise default value from .env file itself
#!/bin/sh
# line endings must be \n, not \r\n !
echo "window._env_ = {" > ./env-config.js
awk -F '=' '{ print $1 ": \"" (ENVIRON[$1] ? ENVIRON[$1] : $2) "\"," }' ./.env >> ./env-config.js
echo "}" >> ./env-config.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment