From 013b44bf90243a0fdc4233ed8730815338886bd6 Mon Sep 17 00:00:00 2001 From: ars Date: Tue, 20 Oct 2020 19:48:22 +0100 Subject: Read variables from conf file. Add example conf file. --- oedquery.conf | 10 ++++++++++ oedquery.sh | 22 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 oedquery.conf diff --git a/oedquery.conf b/oedquery.conf new file mode 100644 index 0000000..a98c46d --- /dev/null +++ b/oedquery.conf @@ -0,0 +1,10 @@ +# Example config + +# Enter your OED API ID and key here +appId= +appKey= + +# Enter desired language here - supported languages: https://developer.oxforddictionaries.com/documentation/languages +language=en-gb +# Desired max synonyms - some entries have a crazy number of them +maxSynonyms=10 diff --git a/oedquery.sh b/oedquery.sh index 043467f..12811c8 100755 --- a/oedquery.sh +++ b/oedquery.sh @@ -2,11 +2,25 @@ read word word=$(echo $word | tr '[:upper:]' '[:lower:]') -appId= -appKey= -language=en-gb +# Create array of variable to read from config file +config=( + appId + appKey + language + maxSynonyms +) +# curl options OPTS='--silent -L -H "app_id: $appId" -H "app_key: $appKey"' -maxSynonyms=10 + +while read line +do + # If config file variable doesn't match variable in config array then ignore it. + if [[ " ${config[@]} " =~ " $(echo "$line" | cut -d '=' -f 1) " ]] + then + # Declare variables + eval $(echo "$line" | cut -d '=' -f 1)=$(echo "$line" | cut -d '=' -f 2-) +fi +done < oedquery.conf # function to provide data to a for loop _jq() { -- cgit v1.2.3