Cover V02, I03
Article
Listing 1
Listing 2
Sidebar 1

may93.tar


Listing 2: The today program

#!/bin/sh
#
#       today
#
#       Show current date, and previous/current/last calendars with
#       current day highlighted
#
#       Lawrence S Reznick -- May 2, 1992

date

NOW=`date '+%m'`
LAST=`expr $NOW - 1`
NEXT=`expr $NOW + 1`
YEAR=`date '+%Y'`
NEXTYEAR=$YEAR
LASTYEAR=$YEAR

if [ $NEXT -gt 12 ]
then
NEXT=1
NEXTYEAR=`expr $YEAR + 1`
fi

if [ $LAST -lt 1 ]
then
LAST=12
LASTYEAR=`expr $YEAR - 1`
fi

cal $LAST $LASTYEAR |
awk '{printf("%-21s\n", $0)}' >$LAST.$$

cal |
sed -e "s/^/ /" -e "s/$/ /" -e "s/ \(`date '+%e'`\) /\<\1\>/" |
awk '{printf("%-21s\n", $0)}' >$NOW.$$

cal $NEXT $NEXTYEAR |
awk '{printf("%-21s\n", $0)}' >$NEXT.$$

paste $LAST.$$ $NOW.$$ $NEXT.$$

rm *.$$