thx man will try it out
Need a dictionary, but don't haveone in your system.
Create the following script called "dict" (or name of your choice).It uses the lynx web browser (freelyavailable on the internet) togo out to dictionary.com and find the word your looking for.
Code:#!/bin/csh -f set word=$1 # lynx is a text-based browser # available free on the web/net. lynx -cfg=/dev/null -dump "http://www.dictionary.com/cgi-bin/dict.pl?term=${word}" | more
thx man will try it out
What is \'Real\' ? How do you define \'Real\' ?
http://users.pandora.be/thefluppe/loddersig.jpg
Wow, I like it :shock:
Cool idea!
Of course, it made me want to write a bash version right away, here it is for those who don't have (t)csh installed:
It uses the 'less' pager instead of 'more', so you can scroll back up (ok, a lot of people probably have alias more="less" in their .bashrc, so to most people it probably won't matter a lot)Code:#!/bin/bash lynx -dump "http://www.dictionary.com/cgi-bin/dict.pl?term=$1" | less
For those who use a pager a lot, I'd recommend to check out 'most' - it definitely beats less or one of the i'm-a-textbrowser-but-also-a-pager apps.
As you probably know, your pager is used to view man pages - here's an example of less versus most:
less pager
most pager
As you can see, 'most' highlights keywords in man pages.
You can set up your pager by modifying the $PAGER environment variable, so in your ~/.bashrc you can write:
export PAGER=/usr/bin/most
BTW I wonder why you specify "-cfg=/dev/null", this would break the script for those who have set up lynx to use a proxy, and *can't* browse the net without a proxy. Any specific reason for this?
Oh, and what does the '-f' do in csh? I don't have a tcsh or csh man page apparently (weird...) and the --help isn't very helpful :-/
I'm kinda bored right now, so I decided to make a "decent" version - yeah I know, almost no improvement or anything, but again, I did it out of pure boredom.
Anyone an idea what's wrong with the dict() function? I wanted to use that after the *), but than it doesn't work... If I call the help() function after *), it works fine, so I must've misconstructed something in the dict()...Code:#!/bin/bash # BASH script created by Ludootje <ludootje at linux dot be> # written on: 09/08/2004 (Belgian date format) # released under the GNU General Public License (a.k.a. GPL) # original csh version written by Mark "mcangeli" Angeli help() { echo "Usage:" echo " --help: display this help." echo " $0 word1 [word2 word3 ... wordn]" echo echo "You can use as many words as you like." echo "When you've read the explanation of the word, hit 'q' to move on to the next word." echo "To exit the program when it's running, hit ^C (i.e. control+c), followed by 'q'." exit 0 } dict() { for i in "$@"; do lynx -dump "http://www.dictionary.com/cgi-bin/dict.pl?term=$i" | less done exit 0 } case $1 in --help) help ;; *) for i in "$@"; do lynx -dump "http://www.dictionary.com/cgi-bin/dict.pl?term=$i" | less done exit 0 esac #EOF
Now I think about it, maybe I should pass arguments to it? But I have no idea how I could determine how many arguments (i.e. words in this case) are passed to the script, so I can't but them in variables. And dict($@) { ... } doesn't work.
Here's one for a thesaurus.
Code:#!/bin/bash lynx -dump "http://www.m-w.com/cgi-bin/thesaurus?book=Thesaurus&va=$1" | less
tryOriginally Posted by Ludootje";p="2296
instead ofCode:for i in $*
Code:for i in $@
I've just written a Q&D dictionary lookup script takes reference.com as base. Features:
- Have both thesaurus and dictionary support
- Omiting trailing (advertisement and unrequired) lines support
Code:#!/bin/sh # dict.sh : Simple command line dictionary. # Requirements : Internet connection to dictionary.com, lynx. # Written by : Volkan YAZICI (a.k.a. `knt') <v0lkany'at'yah*oo~com> # License : GNU GPL (General Public License) # {{{ Variables LYNX="/usr/bin/lynx" FILE_TMP=`mktemp` URL_DICT="http://dictionary.reference.com/search?q=" URL_THES="http://thesaurus.reference.com/search?q=" # }}} # {{{ help() help() { echo "Usage: $0 <-dict|-thes> <word> [<word2> <word3> ...]" exit 0 } # }}} # {{{ Check execution parameters until [ -z "$1" ] do case $1 in "-dict") URL=$URL_DICT ;; "-thes") URL=$URL_THES ;; *) WORD=" $1" ;; esac shift done # }}} # Remove trailing space at the start of the words sentence WORD="`echo $WORD | sed 's/^ //g'`" # Did the user satisfy the requirements? [[ ${#URL} -eq 0 || ${#WORD} -eq 0 ]] && help # Dump web page $LYNX -dump "${URL}${WORD}" 1> $FILE_TMP 2>&1 # {{{ Chop trailing pieces LN_COUNT=`wc -l $FILE_TMP | cut -d' ' -f1` tail -n $[$LN_COUNT - 12] $FILE_TMP 1> $FILE_TMP.0 > $FILE_TMP while read line do [ "`echo $line | grep ADVERTISEMENT`" ] && break echo $line >> $FILE_TMP done < $FILE_TMP.0 # }}} # Dump output rm -f $FILE_TMP.0 cat $FILE_TMP && rm -f $FILE_TMP || echo "FILE_TMP: $FILE_TMP" # vim: set ai tabstop=4 fdm=marker:
Bookmarks