Monday, October 6, 2008

Bash Shell Script To Access The International Thesaurus!

Hey There,

NOTE: As noted in tomorrow's post (???) This is actually a translator mocked up as a multilingual dictionary listed, for some reason, at the online Thesaurus. My sincerest apologies. I'll find a real international Thesaurus soon. A free one, of course :)

Today's Linux/Unix bash shell script is follow-up in our (must-almost-be-ending) series of posts on Linux and Unix Bash shell scripts to keep you from having to switch to your browser ;) The last one we did was an Updated World Weather Checker. To keep up with this list of scripts that keeps on growing, check out our other bash script posts on spewing out famous quotations on pretty much any subject, doing encyclopedia lookups, accessing the online Thesaurus, translating between different languages and, of course, using the online dictionary.

You can run this script just as easily as all the rest of them and it takes a variable number of arguments:

host # ./ithes.sh computer

or

host # ./ithes.sh computer store

Below is a screen shot of the script's output (I'm too tired to keep looking for two word entries that return results from this script or online, so I've just included the error message in the gif below).

Click the picture below to see it in its original form. It's almost exactly the same ;)



Hope you enjoy this script, and can find some use for it. Maybe one day, when all of these scripts have been tweaked, we'll throw those all into one simple menu-based shell script (?). And, as evidenced by the picture above, we'll probably be writing up a script to translate between all the extra characters not included on a standard US keyboard so that the output will show up correctly no matter what character-sets you have installed on your system!

Welcome back to the work week! Chin up! Things probably won't get any worse ;)

Cheers,


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

#!/bin/bash

#
# ithes.sh - Say what you mean. Even if you don't understand it ;)
#
# 2008 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

numargs=$#

if [ $numargs -lt 1 ]
then
echo "Usage: $0 Your Thesaurus Terms"
echo "Ex: $0 fun"
echo "Ex: $0 big fun"
exit 1
fi

if [ $numargs -eq 2 ]
then
args=`echo $args|sed 's/ /\+/g'`
fi

echo

args="$@"
wget=/usr/bin/wget

$wget -nv -O - "http://thesaurus.reference.com/languages?db=languages&lang=EN&continue=y&AR=on&ZH=on&TW=on&CS=on&DK=on&NL=on&ET=on&FI=on&FR=on&DE=on&EL=on&HU=on&IS=on&ID=on&IT=on&JA=on&KO=on&LV=on<=on&NO=on&PL=on&BR=on&PT=on&RO=on&RU=on&SK=on&SL=on&ES=on&SV=on&TR=on&q=$args" 2>&1|grep -i "No results found" >/dev/null 2>&1

anygood=$?

if [ $anygood -eq 0 ]
then
args=`echo $args|sed 's/%20/ /g'`
echo "No results found for $args"
exit 2
fi

$wget -nv -O - "http://thesaurus.reference.com/languages?db=languages&lang=EN&continue=y&AR=on&ZH=on&TW=on&CS=on&DK=on&NL=on&ET=on&FI=on&FR=on&DE=on&EL=on&HU=on&IS=on&ID=on&IT=on&JA=on&KO=on&LV=on<=on&NO=on&PL=on&BR=on&PT=on&RO=on&RU=on&SK=on&SL=on&ES=on&SV=on&TR=on&q=$args" rel="nofollow" 2>&1|sed -e :a -e 's/<[^>]*>/ /g;/</N;//ba' -e 's/$/\n/'|sed -e '1,/Multilingual/d' -e '/See also/,$d'|sed -e '/^[ \t]*$/d' -e '/^$/N;/\n$/D'

exit 0