Download this file
#!/bin/ksh
# Removes items from your $HOME/.todo list
# Written by Wayne Pollock, Tampa Florida 1997
#set -x # uncomment this line to turn on debuging mode!
PATH=/bin
umask 077
FILE=$HOME/.todo
TempFile=/tmp/todo.$$
rev=$(tput rev) # The byte string to turn on reverse video mode
norm=$(tput rmso) # The byte string to turn off reverse video mode
if [ $# != 1 ]
then
echo "$rev ### Error: type 'didit #' to remove item # from todo list" >&2
echo $norm >&2
exit -1
fi
if [ ! -s $FILE ]
then
echo "The todo list is empty; there's nothing to do!" >&2
echo >&2
exit -1
fi
sed "$1 d" <$FILE >$TempFile 2>/dev/null
# Checking that the new file size is exactly one less than the old file size:
OLD_SIZE=$(cat $FILE |wc -l) # Note how to run a command, saving the
NEW_SIZE=$(cat $TempFile |wc -l) # output in a string!
if [ "$OLD_SIZE" != "$(($NEW_SIZE + 1))" ] # Note the in-line arithmetic!
then
echo "$rev ### Error: todo file not modified!" >&2
echo $norm >&2
rm -f $TempFile 2>/dev/null
exit -1
fi
mv $TempFile $FILE