Linux, Unix, /etc

Danger Will Robinson! You are now entering a condescending Unix user zone!
Sponsored links (requires javascript):

Scripts: Handy "Desktop" Thingies

calc: use bc to do sums on the command line

There is limited maths support right at the ksh command line. For more complicated stuff, though, it's nice not have to fire up a special program. This script lets you do arbitarily-complex calculations on the command line by piping through the GNU "basic calculator" bc.

 
#!/bin/sh
#calc: use bc to calculate any legal bc mathematical expression
case $2 in
    "") SCALE=2 ;;
    *) SCALE=$2 ;;
esac
(echo scale=$SCALE;echo "$1")|bc

$ calc "(10*4/2)+3"
23.00
$


todo: print a list of things to do today

I keep a file called "todo" in my home directory. I fill it with a set of headers produced by dateseries, seperated by blank lines by double). Then write up what I have to do when. This script then gives me a list of tasks scheduled for the day it's run. Simple, but useful.

 
#!/bin/sh
#todo: print a list of things to do today

todofile=$HOME/todo

cvtday()
{
case $day in
    01) day=1;;
    02) day=2;;
    03) day=3;;
    04) day=4;;
    05) day=5;;
    06) day=6;;
    07) day=7;;
    08) day=8;;
    09) day=9;;
esac
case $day in
    1?) day=$day"th";;
    *1) day=$day"st";;
    *2) day=$day"nd";;
    *3) day=$day"rd";;
    *) day=$day"th";;
esac
}

set `date +'%A %d %B %Y'`
day=$2
cvtday
today="$1 $day $3 $4"
set `date +'%A %d %B %Y' —date '1 day'`
day=$2
cvtday
tomorrow="$1 $day $3 $4"
sed -n -e '/'"$today"'/,/'"$tomorrow"'/p' < $todofile | sed -e '/'"$tomorrow"'/d' 


crafty: an interface to the Robert Hyatt's "crafty" chess program

Crafty is the direct descendant of Cray Blitz, and a tough opponent, rated around 2300. Here's a simple script to make playing chess with it a bit easier.

#!/bin/sh
cd $HOME/chess || exit 1
case $1 in
	"")
		echo 1>&2 'no arg: using level 5 (5 mins per side)'
		time='time sd/5';ponder='ponder off' ;;
	[1-9]*)
		time='time sd/$1';ponder='ponder off' ;;
	blitz)
		time='time sd/5';ponder='ponder on' ;;
	quick)
		time='time sd/30';ponder='ponder on' ;;
	tourney)
		time='time 40/150/30/60';ponder='ponder on' ;;
	*)
		echo 1>&2 'invalid arg: using level 5 (5 mins per side)'
		time='time sd/5';ponder='ponder off' ;;
esac
replace 'time .*' "$time" .craftyrc
replace 'ponder .*' "$ponder" .craftyrc
exec /usr/local/bin/crafty


[back to Scripts index] [back to Linux, Unix, etc] [Main Site] [Weblog]



Contents licensed under the GPL