#!/bin/sh # # dict - a commandline-frontend for LEO.ORGs Dictionary Service # by Raphael Becker # # This script is distributed under the BSD-License. # # Version 0.2.1 # # http://rabe.uugrn.org/scripts/dict2 # and see also my "4x72-compressed" version of this # script for use as a mail/news-signature under # http://rabe.uugrn.org/scripts/dict2_signature # ############################################################### t(){ # This function does the translation. # Syntax: t word [word [word [...]]] with a maximum of 9 # word on some implementations of /bin/sh # while theres a word to translate ... while [ -n "$1" ]; do # need a temp file T=/tmp/$$.html # fetch translation, give first word by http-GET method lynx -source "http://dict.leo.org/?search=$1"|\ grep search\ results >$T # ... and grep for the line in the html-source we are #looking for # pick up that piece of code with w3m and render # the table. newer versions of lynx are able to # render tables correctly, but w3m is the safe way. w3m -dump $T # delete temp file rm $T # next we want to have $2 as $1, to get the translation for # the next word. if ther's no next word $1 becomes empty # and the while-loop will exit. shift # END of while done # END of function } # The following is the main # check out if ther's a commandline-parameter to this script. # if set, then translate all words "$@" with t() and exit [ -n "$1" ]&&\ #simply translate t "$@"||\ # no parameter, so enter the interactive mode. prompt for # a word. Note that '\> W' is not a redirection into the file W # the while-loop will exit if "read" is no more "true". This # happens typically at the end-of-file or ^D (interactive Ctrl-D) while read -ep dict2\> W; do # translate the words. If output is larger than terminal has # lines 'more' will prompt you for a key. t $W|more done #by rhb