From c2e739c7f2337ce37b84de4e0c5921702347009f Mon Sep 17 00:00:00 2001 From: ars Date: Tue, 20 Oct 2020 19:48:55 +0100 Subject: Re add full stop and quotes to _define output that were lost in earlier commit. Add error handling in _thes when no synonyms are returned. --- oedquery.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/oedquery.sh b/oedquery.sh index 12811c8..b99cf0a 100755 --- a/oedquery.sh +++ b/oedquery.sh @@ -67,11 +67,11 @@ _define() { for json in $(echo "${result}" | jq -r '.results[].lexicalEntries[] | @base64') do output="$output $(_jq '.lexicalCategory.text'): " - output="$output $(_jq '.entries[0].senses[0].definitions[0]') " + output="$output $(_jq '.entries[0].senses[0].definitions[0]'). " examplePhrase=$(_jq '.entries[0].senses[0].examples[0].text') if [[ "$examplePhrase" != "null" ]] then - output=$output" "$examplePhrase + output=$output" \"$examplePhrase\"" fi done echo $output @@ -95,7 +95,7 @@ _etym() { _thes() { _getdata count=0 - for json in $(echo "${result}" | jq -r '.results[].lexicalEntries[0].entries[0].senses[0].synonyms[] | @base64'); do + for json in $(echo "${result}" | jq -r '.results[].lexicalEntries[0].entries[0].senses[0].synonyms[]? | @base64'); do output="$output $(_jq '.text'), " ((count=count+1)) # Limit output to a resonable number of synonyms @@ -104,10 +104,17 @@ _thes() { break fi done - # remove trailing comma and space - output=$(echo $output | sed '$s/,$//') - echo $output - exit 0 + + if [[ -z $output ]] + then + echo "No synonyms found." + exit 0 + else + # remove trailing comma + output=$(echo $output | sed '$s/,$//') + echo $output + exit 0 + fi } # Get URL for first audio file in returned data -- cgit v1.2.3