#!/bin/bash #年と月の入力を促す echo Enter your "year" and "month" #年と月の読み込み read year month #年と月の出力 echo $year 年 $month 月 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月の設定 if [ $m = 14 ] then q=28 if [ $y4 = 0 ] then q=`expr $((q+1))` elif [ $y100 = 0 ] then q=`expr $((q-1))` elif [ $y400 = 0 ] then q=`expr $((q+1))` fi #1,3,5,7,8,10,12月の設定 else 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 ] then q=31 #それ以外の月の設定 else q=30 fi fi #カレンダーの出力設定 printf " %s %s %s %s %s %s %s\n" 日 月 火 水 木 金 土 if [ $h = 0 ] then printf " 1\n" elif [ $h = 2 ] then printf " 1 2 3 4 5 6\n" elif [ $h = 3 ] then printf " 1 2 3 4 5\n" elif [ $h = 4 ] then printf " 1 2 3 4\n" elif [ $h = 5 ] then printf " 1 2 3\n" elif [ $h = 6 ] then printf " 1 2\n" fi if [ $h -eq 0 -o $h -eq 1 ] 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 else i2=`expr $((i%7))` if [ $i2 = $i1 ] then printf "%3d\n" $i else printf "%3d" $i fi fi i=`expr $((i+1))` done