Skip to content

Instantly share code, notes, and snippets.

@touv
Created May 14, 2018 09:42
Show Gist options
  • Save touv/bea3a29252f8ba1b1f4842742d9e675e to your computer and use it in GitHub Desktop.
Save touv/bea3a29252f8ba1b1f4842742d9e675e to your computer and use it in GitHub Desktop.
Exemple de passage du JSON vers des variables BASH
#!/bin/sh
# "DATABASES": [
# {
# "MYSQL_DATABASE": "database1",
# "MYSQL_USER": "user",
# "MYSQL_PASSWORD": "toto"
# },
# {
# "MYSQL_DATABASE": "database2",
# "MYSQL_USER": "user",
# "MYSQL_PASSWORD": "truc"
# }
# ]
#
#
#
IN=`jq -r '.DATABASES[] | "\(.MYSQL_DATABASE) \(.MYSQL_USER) \(.MYSQL_PASSWORD) ;"' ./config.json`
forEachDatabase() {
echo "arg1: ${1}; arg2:${2}; arg3:${3}"
}
while IFS=';' read -ra ITEM; do
for i in "${ITEM[@]}"; do
forEachDatabase $i
done
done <<< "$IN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment