My shell scripts #1 - Wikipedia search

I will publish my creations here, just in case someone finds them useful. My scripts are made for the ash shell, so they should work in most of the other shells. I run them on my OpenWrt router with 400MHz CPU and 32MB RAM with no problems :).

The first one I'm going to publish is a Wikipedia search script, requiring only "dig" and "sed" programs. Usage is fairly simple, just type:

$ ./wiki.sh hello world


The script automatically replaces all spaces with underscores. And now the actual code:

#!/bin/ash
if [ ! -n "$1" ]
then
  echo "What are you searching for?"
  echo "Usage:"
  echo "  $0 keyword"
  exit 1
fi
q=`echo $* | sed 's/\ /\_/g'`
dig +short txt $q.wp.dg.cx | sed 's/\"\ \"//'
exit 0

No comments:

Post a Comment