#!/bin/bash echo "Type YEAR(A.D.) and MONTH (ex1999 7" read ye mo days=( 0 0 31 30 31 30 31 31 30 31 30 31 31 28 ) #各月の末日 Y=$ye M=$mo if [ $M = 1 -o $M = 2 ]; then Y=`expr $Y - 1` M=`expr $M + 12` fi if [ `expr $ye % 4` = 0 -a `expr $ye % 100` != 0 ]; then #うるう年の場合の補正 days[13]=29 fi if [ `expr $ye % 400` = 0 ] ; then days[13]=29 fi da=${days[$M - 1]} #表示月の末日決定 J=`expr $Y '/' 100` #ツェラーの公式 K=`expr $Y % 100` A=`expr $M + 1` B=`expr $A '*' 26` C=`expr $B '/' 10` D=`expr $K '/' 4` E=`expr $J '/' 4` F=`expr $J '*' 2` I=`expr 1 + $C + $K + $D + $E - $F` Q=`expr $I + 70000` #負の数を割る処理の防止 H=`expr $Q % 7` printf "%4s %4s %4s %4s %4s %4s %4s\n" Sun Mon Tue Wed Thu Fri Sat #カレンダーの行事 if [ $H = 0 ] ; then S=2 printf "%4s %4s %4s %4s %4s %4s %4s\n" " " " " " " " " " " " " " 1" elif [ $H = 1 ] ; then S=8 printf "%4s %4s %4s %4s %4s %4s %4s\n" " 1" " 2" " 3" " 4" " 5" " 6" " 7" elif [ $H = 2 ] ; then S=7 printf "%4s %4s %4s %4s %4s %4s %4s\n" " " " 1" " 2" " 3" " 4" " 5" " 6" elif [ $H = 3 ] ; then S=6 printf "%4s %4s %4s %4s %4s %4s %4s\n" " " " " " 1" " 2" " 3" " 4" " 5" elif [ $H = 4 ] ; then S=5 printf "%4s %4s %4s %4s %4s %4s %4s\n" " " " " " " " 1" " 2" " 3" " 4" elif [ $H = 5 ] ; then S=4 printf "%4s %4s %4s %4s %4s %4s %4s\n" " " " " " " " " " 1" " 2" " 3" elif [ $H = 6 ] ; then S=3 printf "%4s %4s %4s %4s %4s %4s %4s\n" " " " " " " " " " " " 1" " 2" fi t=0 O=$S while [ $t -le 5 ] do if [ $O -le $da ] ; then S1=$O O=`expr $O + 1` else S1=" " fi if [ $O -le $da ] ; then S2=$O O=`expr $O + 1` else S2=" " fi if [ $O -le $da ] ; then S3=$O O=`expr $O + 1` else S3=" " fi if [ $O -le $da ] ; then S4=$O O=`expr $O + 1` else S4=" " fi if [ $O -le $da ] ; then S5=$O O=`expr $O + 1` else S5=" " fi if [ $O -le $da ] ; then S6=$O O=`expr $O + 1` else S6=" " fi if [ $O -le $da ] ; then S7=$O O=`expr $O + 1` else S7=" " fi printf "%4s %4s %4s %4s %4s %4s %4s\n" $S1 $S2 $S3 $S4 $S5 $S6 $S7 t=`expr $t + 1` done