Last active
June 9, 2023 16:10
-
-
Save versionsix/8305541cdec2d2b3b0b512add252b790 to your computer and use it in GitHub Desktop.
Azure BASH parse connection string example
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
#!/bin/bash | |
declare -x MYSQLCONNSTR_MS_Mysql="Database=mydevwiki; Data Source=mw-mysql; User Id=root; Password=mysecretpassword" | |
declare -A mysqlconn | |
# Strip spaces, then convert semicolon to spaces to loop in array | |
# We must strip spaces since this is inconsistent used inside azure | |
for keyvaluepair in $(echo $MYSQLCONNSTR_MS_Mysql | sed "s/ //g; s/;/ /g") | |
do | |
ARR=(${keyvaluepair//=/ }) | |
mysqlconn[${ARR[0]}]=${ARR[1]} | |
done | |
for i in "${!mysqlconn[@]}" | |
do | |
echo "key :" $i | |
echo "value:" ${mysqlconn[$i]} | |
echo "--------" | |
done | |
echo "For example get value of key Database:" | |
echo ${mysqlconn[Database]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment