Skip to content

Instantly share code, notes, and snippets.

@versionsix
Last active June 9, 2023 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save versionsix/8305541cdec2d2b3b0b512add252b790 to your computer and use it in GitHub Desktop.
Save versionsix/8305541cdec2d2b3b0b512add252b790 to your computer and use it in GitHub Desktop.
Azure BASH parse connection string example
#!/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