diff options
-rwxr-xr-x | oedquery.sh | 21 |
1 files 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 |