#!/bin/bash
echo "菴募ケエ繝サ菴墓怦縺ョ繧ォ繝ャ繝ウ繝繝シ繧定。ィ遉コ縺励∪縺吶°��"
echo "隘ソ證ヲ菴募ケエ��(謨ー蟄励�縺ソ蜈・蜉�)"
read year
echo "菴墓怦��(謨ー蟄励�縺ソ蜈・蜉�)"
read month
#竊大ケエ縲∵怦繧定◇縺�
if [ $year -lt 1 -o $year -gt 9999 ]#隘ソ證ヲ0蟷エ莉・蜑阪�10000蟷エ莉・髯阪→險繧上l繧九→
then echo "險育ョ励〒縺阪∪縺帙s"#繧ィ繝ゥ繝シ繝。繝�そ繝シ繧ク
exit#邨ゆコ�
elif [ $month -lt 1 -o $month -gt 12 ]#0譛井サ・蜑阪�13譛井サ・髯阪→險繧上l繧九→
then echo "險育ョ励〒縺阪∪縺帙s"#繧ィ繝ゥ繝シ繝。繝�そ繝シ繧ク
縲縲縲exit#邨ゆコ�
fi
if [ $month = 1 -o $month = 2 ];then#繧ゅ@1譛医°2譛医�縺ィ縺阪�
Y=`expr $year -1`#蟷エ縲∵怦繧貞燕蟷エ縺ョ13譛医�14譛医→閠�∴繧�
M=`expr $month + 12`
else#縺昴l莉・螟悶�譛医↑繧�
Y=$year#縺昴�縺セ縺セ
M=$month
fi
#莉・荳九ヤ繧ァ繝ゥ繝シ縺ョ蜈ャ蠑上�險育ョ�
#1譌・縺ョ譖懈律繧呈アゅa繧�
J=`expr $Y / 100`
K=`expr $Y % 100`
j=`expr $J / 4`
k=`expr $K / 4`
m=`expr \( $M + 1 \) \* 26 / 10`
j2=`expr $J \* 2`
H=`expr 1 + $m + $K + $k + $j - $j2`
L=`expr $H % 7`
if [ $L -lt 0 ]#菴吶j縺瑚イ�縺ョ縺ィ縺�
then
h=`expr $L + 7`#+7縺ァ豁」縺ォ縺吶k
else#繧ゅ→繧ゅ→豁」縺ェ繧�
h=$L#縺昴�縺セ縺セ
fi
#髢丞ケエ縺九←縺�°閠�∴繧�
ye=`expr $year / 100`#縺サ繧薙→縺ョ蟷エ縺ョ荳�2譯�
ar=`expr $year % 100`#荳�2譯�
uY=`expr $year % 4`#縺サ繧薙→縺ョ蟷エ繧�4縺ァ蜑イ縺」縺溘≠縺セ繧�
uy=`expr $ye % 4`#縺サ繧薙→縺ョ蟷エ縺ョ荳�2譯√r4縺ァ蜑イ縺」縺溘≠縺セ繧�
urutest1=`test $uY = 0 -a $ar -ne 0 ; echo $?`#4縺ァ蜑イ繧雁�繧後√°縺、100縺ァ蜑イ繧雁�繧後↑縺�°繝�せ繝�
urutest2=`test $ar = 0 -a $uJ = 0 ; echo $?`#400縺ァ蜑イ繧雁�繧後k縺九ユ繧ケ繝�
if [ \( $urutest1 = 0 -o $urutest2 = 0 \) -a $M = 14 ];then#繧ゅ@髢丞ケエ縺九←縺�°縺ョ繝�せ繝医�縺ゥ縺。繧峨°縺檎悄縺ァ縲√°縺、2譛医r陦ィ遉コ縺吶k縺ェ繧�
matsu=29#譛ォ譌・縺ッ29譌・
elif [ $M = 4 -o $M = 6 -o $M = 9 -o $M = 11 ];then#4,6,9,11譛医↑繧�
matsu=30#譛ォ譌・縺ッ30譌・
elif [ $M = 14 ];then#縺オ縺、縺��2譛医↑繧�
matsu=28#譛ォ譌・縺ッ28譌・
else#縺昴l莉・螟悶�
matsu=31#譛ォ譌・縺ッ31譌・
fi
printf "%16s %12s\n" $year蟷エ $month譛�#繧ォ繝ャ繝ウ繝繝シ縺ョ陦ィ遉コ
printf "%4s %4s %4s %4s %4s %4s %4s\n" Sun Mon Tue Wed Thu Fri Sat
#1譌・縺ョ蜑阪�遨コ逋ス縺ョ謨ー繧偵°縺槭∴繧�
if [ $h = 0 ];then#1譌・縺悟悄譖懊↑繧�
sp=6#遨コ逋ス6縺、
else sp=`expr $h - 1`#縺昴l莉・螟也ゥコ逋ス縺ッ(h-1)蛟�
fi
#遨コ逋ス繧地um[x]縺ョ蠖「縺ォ謨エ逅�
kuuhaku=1#雋ッ驥醍ョア"kuuhaku"繧偵▽縺上▲縺ヲ1縺九i髢句ァ�
while :
do
if [ $kuuhaku -gt $sp ];then#"kuuhaku"縺ョ荳ュ霄ォ縺ョ謨ー蟄励′莠亥ョ壹@縺溽ゥコ逋ス繧医j螟壹¥縺ェ縺」縺溘i
break#繝ォ繝シ繝励°繧画栢縺代k
fi
num[ $kuuhaku ]=" "#num["kuuhaku"]縺ォ縺ッ遨コ逋ス繧貞�繧後k
kuuhaku=`expr $kuuhaku + 1`#縺薙l縺セ縺ァ縺ョ"kuuhaku"縺ォ1雜ウ縺�
done
#譌・莉倥r蜷梧ァ倥↓縺励※謨エ逅�☆繧�
hinichi=1#雋ッ驥醍ョア"hinichi"繧偵▽縺上▲縺ヲ1縺九i髢句ァ�
while :
do
if [ `expr $hinichi + $sp` -gt 42 ];then#"hinichi"縺ョ荳ュ霄ォ縺ョ謨ー縺ィ遨コ逋ス縺ョ謨ー繧定カウ縺励◆繧ゅ�縺�42莉・荳翫↓縺ェ縺」縺溘i
break#繝ォ繝シ繝励°繧画栢縺代k
fi#(6騾ア髢薙�繧謎クヲ縺ケ繧峨l繧九h縺�↓縺励◆)
if [ $hinichi -gt $matsu ];then#"hinichi"縺瑚ィュ螳壹@縺滓忰譌・繧医j螟ァ縺阪¥縺ェ繧九→
num[ `expr $hinichi + $sp` ]=" "#縺昴l莉・髯阪�遨コ逋ス繧定。ィ遉コ
else#譛蛻昴�縺サ縺�"hinichi"縺梧忰譌・繧医j蜑阪�縺ィ縺�
num[ `expr $hinichi + $sp` ]=$hinichi#num[遨コ逋ス縺ョ謨ー�吃inichi]縺ォ縺ッ"hinichi"繧貞�繧後k
hinichi=`expr $hinichi + 1`#"hinichi"縺ォ1雜ウ縺励※谺。縺ョ繝ォ繝シ繝�
done#縺薙%縺ァnum[x]縺ョx縺ッ遨コ逋ス縺ョ謨ー縺ョ蛻�★繧峨@縺ヲ縺�k
#縺ェ繧峨∋繧�
printf "%4s %4s %4s %4s %4s %4s %4s\n" "${num[1]}" "${num[2]}" "${num[3]}" "${num[4]}" "${num[5]}" "${num[6]}" "${num[7]}"
printf "%4d %4d %4d %4d %4d %4d %4d\n" "${num[8]}" "${num[9]}" "${num[10]}" "${num[11]}" "${num[12]}" "${num[13]}" "${num[14]}"
printf "%4d %4d %4d %4d %4d %4d %4d\n" "${num[15]}" "${num[16]}" "${num[17]}" "${num[18]}" "${num[19]}" "${num[20]}" "${num[21]}"
printf "%4d %4d %4d %4d %4d %4d %4d\n" "${num[22]}" "${num[23]}" "${num[24]}" "${num[25]}" "${num[26]}" "${num[27]}" "${num[28]}"
printf "%4s %4s %4s %4s %4s %4s %4s\n" "${num[29]}" "${num[30]}" "${num[31]}" "${num[32]}" "${num[33]}" "${num[34]}" "${num[35]}"
printf "%4s %4s %4s %4s %4s %4s %4s\n" "${num[36]}" "${num[37]}" "${num[38]}
" "${num[39]}" "${num[40]}" "${num[41]}" "${num[42]}"
#邨ゆコ�
蜑阪�繝シ繧ク縺ク