#!/usr/bin/bash
year=0
printcalendar()
{
year=$1
week=$2
months=('January' 'February' 'March' 'April' 'May' ' June' 'July' 'August' 'September' 'October' 'November' 'December')
weeks=('Sun' 'Mon' 'Tue' 'Wen' 'Thu' 'Fri' 'Sat')
days=(31 28 31 30 31 30 31 31 30 31 30 31)
#for m in ${months[@]};
#do
# echo -n $m
#done
today=`date +%m-%d`
todaymonth=`echo $today | awk -F '-' '{print $1}'`
todayday=`echo $today | awk -F '-' '{print $2}'`
m=0
d=1
while [ $m -lt 12 ]
do
printf "< %-10s %-9i>\n" ${months[$m]} $year
for w in ${weeks[@]};
do
echo -n $w' '
done
echo ''
printf "%`expr $week \* 4`s" ' '
d=1
w=`expr $week + 0`
while [ $d -le ${days[$m]} ]
do
while [ $w -lt 7 -a $d -le ${days[$m]} ]
do
if [ `expr $m + 1` -eq $todaymonth -a $d -eq $todayday ]; then
printf " "
printf "\033[7m%2s\033[0m" $d
printf " "
else
printf "%3s " $d
fi
w=`expr $w + 1`
d=`expr $d + 1`
done
echo ''
week=`expr $w % 7`
w=0
done
m=`expr $m + 1`
echo ''
#break
done
}
getdays()
{
year=$1
y=1
days=1
while [ $y -lt $year ]
do
if [ `expr $y % 4` -eq 0 -a `expr $y % 100` -ne 0 ]; then
days=`expr $days + 1`
elif [ `expr $y % 400 ` -eq 0 ]; then
days=`expr $days + 1`
fi
days=`expr $days + 365 % 7`
y=`expr $y + 1`
done
echo $days
}
main()
{
year=$1
days=`getdays $year`
week=`expr $days % 7`
printcalendar $year $week
}
if [ $# -lt 1 ]; then
year=2015
else
year=$1
fi
today=`date +%m-%d`
todaymonth=`echo $today | awk -F '-' '{print $1}'`
todayday=`echo $today | awk -F '-' '{print $2}'`
echo $todayday
echo $todaymonth
main $year