#!/bin/bash #年と月の入力を促す echo Enter your "year" and "month" #年と月の読み込み read year month #年と月の出力 echo $year 年 $month 月 > quiz2.txt y=$year m=$month #うるう年かどうかの計算 y4=`expr $((y%4))` y100=`expr $((y%100))` y400=`expr $((y%400))` #もし1月か2月ならば if [ $m -eq 1 -o $m -eq 2 ] #年は1年ひき、月は12カ月たす then y=`expr $((y-1))` m=`expr $((m+12))` fi #ツェラーの公式の計算 j=`expr $((y/100))` k=`expr $((y%100))` m1=`expr $((m+1))` h1=`expr $((1+m1*26/10+k+k/4+j/4-2*j))` h=`expr $((h1%7))` if [ $h -lt 0 ] then h=`expr $((h+7))` fi #2月のとき、m=14として if [ $m -eq 14 ] then if [ $y4 -ne 0 ] #日にちq=28日 then q=28 #もし、うるう年ならば elif [ $y100 -eq 0 -a $y400 -ne 0 ] #q=28日までありますよ。 then q=28 #そのほかの日は29日までですよ。 else q=29 fi fi #1,3,5,7,8,10,12月のとき if [ $m -eq 1 -o $m -eq 3 -o $m -eq 5 -o $m -eq 7 -o $m -eq 8 -o $m -eq 10 -o $m -eq 12 ] #31日までありますよ。 then q=31 fi if [ $m -eq 4 -o $m -eq 6 -o $m -eq 9 -o $m -eq 11 ] #それ以外の月のとき、30日までありますよ。 then q=30 fi #カレンダーの出力設定 #日~土曜を出力 printf " %s %s %s %s %s %s %s\n" 日 月 火 水 木 金 土 >> quiz2.txt #もしh=0ならば、土曜日に出力 if [ $h = 0 ] then printf " 1\n" >> quiz2.txt #h=2ならば月曜から出力 elif [ $h = 2 ] then printf " 1 2 3 4 5 6\n" >> quiz2.txt #h=3ならば火曜から出力 elif [ $h = 3 ] then printf " 1 2 3 4 5\n" >> quiz2.txt #h=4ならば水曜から出力 elif [ $h = 4 ] then printf " 1 2 3 4\n" >> quiz2.txt #h=5ならば木曜から出力 elif [ $h = 5 ] then printf " 1 2 3\n" >> quiz2.txt #h=6ならば金曜から出力 elif [ $h = 6 ] then printf " 1 2\n" >> quiz2.txt fi #h=0またはh=1ならば if [ $h -eq 0 -o $h -eq 1 ] #h=h+7としてあげて then h=`expr $((h+7))` fi #改行の位置決定 i=`expr $((9-h))` i1=`expr $((8-h))` while [ $i -le $q ] do if [ $i = $q ] then printf "%3d\n" $i >> quiz2.txt else i2=`expr $((i%7))` if [ $i2 = $i1 ] then printf "%3d\n" $i >> quiz2.txt else printf "%3d" $i >> quiz2.txt fi fi i=`expr $((i+1))` done more quiz2.txt