Last active
February 16, 2019 09:01
-
-
Save mogul/b266c7cf37f88ee27ae31580da511bf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bash-3.2$ DATABASE_URL='postgres://username:password@hostname.net:port/dbname' | |
bash-3.2$ [[ $DATABASE_URL =~ (.*)'://'(.*):(.*)@(.*):(.*)/(.*) ]] && \ | |
DB_USERNAME=${BASH_REMATCH[2]} \ | |
DB_PASSWORD=${BASH_REMATCH[3]} \ | |
DB_HOST=${BASH_REMATCH[4]} \ | |
DB_PORT=${BASH_REMATCH[5]} \ | |
DB_DBNAME=${BASH_REMATCH[6]} env |grep DB_ | |
DB_PORT=port | |
DB_USERNAME=username | |
DB_DBNAME=dbname | |
DB_PASSWORD=password | |
DB_HOST=hostname.net |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regex for extracting individual elements of a postgres URI and assigning them to environment variables so they can be passed into a program individually