Search wikipedia from the command line

Dec 06, '04 09:45:00AM

Contributed by: Anonymous

I am probably not the only one to be overcome with the delights and wonders of wikipedia.org. However, searching my favourite encyclopaedia is a bit of a chore. The wikipedia.org main page is slow at the best of times. I'd rather have something like my google bar that would allow me to type in a query (XFS, for example) and then boom!, up comes a page telling me all about XFS. So I wrote a script that does exactly that:

#!/bin/bash
open http://en.wikipedia.org/wiki/Special:\
Search?search=$(echo $@ | sed 's/\ /+/g')
After saving that to a file (I called mine wikipedia) and running chmod 755 wikipedia to make it executable, place it in your command path (I use ~/bin). Now all you have to do to search for wikipedia entries with references to dogs with pockets is go to the terminal and type:
$ wikipedia dogs with pockets
You can probably think of more useful things to search for...

[robg adds: I broke the script's one line of code into two to make it narrower for display here. The backslash should let you copy and paste it, and it will work just fine. If this bothers your sense of aesthetics, though, just remove the backslash and the line break. Do not put a space between the : and the S.]

Comments (16)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041204025436909