Monday, September 22, 2008

Famous Quotations Script For Linux and Unix

Hey There,

Today's Linux/Unix bash shell script is yet another follow up to a whole cavalcade of scripts we've written to mine the knowledge on tap at, although this one is grabbing its material from If you missed any of the others, you can still find them in our older bash script posts to do encylopedia lookups, access the online Thesaurus, translate between different languages and, of course, the use the online dictionary. This time we're going to take a crack at grabbing some famous quotes for those moments when you just can't think of what someone else may have said about something ;)

This script is fairly easy to run and somewhat limited. The only real limitation is that it will only return the first pages of quotes from Hopefully that should be enough since they seem to put the best ones near the top of the list. You can run it with one or multiple arguments, like so:

host # ./ money


host # ./ love of money

Like all of our previous scripts, this script uses wget and sed to get the job done. As almost-usual, this script is a work in progress and could use some sprucing up, but, hopefully, it's good enough for you to enjoy :)

Below are a few screen shots of the script's output, demonstrating the output of the command examples show above.

Be sure to click on either of these pictures to see in them in Giganti-Size :)

Hope you enjoy this script, and can find some use for it. Any suggestions for improvement would be greatly appreciated.

As Amanda Cross put it: The point of quotations is that one can use another's words to be insulting

Here's to sounding more erudite than I am ;)


Creative Commons License

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


# - Why not be witty? ;)
# 2008 - Mike Golvach -
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

if [ $# -lt 1 ]
echo "Usage: $0 Your Word(s) To Find A Quote"
echo "May be two or more words separated by spaces"
echo "but only one definition per execution."
echo "Ex: $0 money"
echo "Ex: $0 love of money"
exit 1


if [ $# -gt 1 ]
args=`echo $args|sed 's/ /\+/g'`


$wget -nv -O - "$args&startsearch=Search&Author=&C=mgm&C=motivate&C=classic&C=coles&C=poorc&C=lindsly&C=net&C=devils&C=contrib" 2>&1|grep -i "No quotations found" >/dev/null 2>&1


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

$wget -nv -O - "$args&startsearch=Search&Author=&C=mgm&C=motivate&C=classic&C=coles&C=poorc&C=lindsly&C=net&C=devils&C=contrib" 2>&1|sed -e :a -e 's/<[^>]*>/ /g;/</N;//ba' -e 's/$/\n/'|sed -e '1,/Results from/d' -e '/Results of search for */,$d'|sed 's/^[ \t]*//;s/[ \t]*$//'|sed '/^$/N;/\n$/D'|sed '/Pages: /,$d'|sed '/Results from/,$d'|sed 's/^ *//;s/ *$//;s/ \{1,\}/ /g'|sed 's/More quotations on: .*$//'

exit 0