#!/bin/bash echo "Enter your YEAR and MONTH." #「Enter your YEAR and MONTH.」と表示させる。 read year month #入力された年と月を読み込む。 if [ $month = 1 ] #入力された月が1月か2月なら then year2=`expr $year - 1` #前年の month2=13 #13月(1月)か14月(2月)とし、 elif [ $month = 2 ] then year2=`expr $year - 1` month2=14 else year2=$year #それ以外はそのまま month2=$month fi #もし、入力された月が2月ならうるう年による一か月当たりの日数補正を行う↓ if [ $month = 2 ] then if [ $(($year % 400)) = 0 ] then days=29 elif [ $(($year % 100)) = 0 ] then days=28 elif [ $(($year % 4)) = 0 ] then days=29 else days=28 fi fi #入力された月の日数を決定する if [ $month -ne 2 ] then if [ $month = 1 ] then days=31 elif [ $month = 3 ] then days=31 elif [ $month = 5 ] then days=31 elif [ $month = 7 ] then days=31 elif [ $month = 8 ] then days=31 elif [ $month = 10 ] then days=31 elif [ $month = 12 ] then days=31 else days=30 fi fi #まず入力された年と月をquiz2.txtに出力する↓ printf " $year年 $month月\n日 月 火 水 木 金 土\n" > ../results/quiz2.txt printf " $year年 $month月\n日 月 火 水 木 金 土\n" #ここからツェラーの公式を利用した曜日決定を行う↓ q=1 while [ $q -le $days ] do J=`expr $year2 / 100` K=`expr $year2 % 100` t1=`expr \( $month2 + 1 \) \* 26 / 10` t2=`expr $K / 4` t3=`expr $J / 4` h=`expr \( 6 + $q + $t1 + $K + $t2 + $t3 - \( 2 \* $J \) \) % 7` #「h」が負の場合の補正を行う if [ $h -lt 0 ] then h=`expr $h + 7` fi #一周間の日にちを決定する while [ $h -le 6 ] do case $h in 0) if [ $q -le $days ] then su=$q else su=' ' fi ;; 1) if [ $q -le $days ] then mo=$q else mo=' ' fi ;; 2) if [ $q -le $days ] then tu=$q else tu=' ' fi ;; 3) if [ $q -le $days ] then we=$q else we=' ' fi ;; 4) if [ $q -le $days ] then th=$q else th=' ' fi ;; 5) if [ $q -le $days ] then fr=$q else fr=' ' fi ;; 6) if [ $q -le $days ] then sa=$q else sa=' ' fi ;; esac h=`expr $h + 1` q=`expr $q + 1` done #一週間分が終わったら結果をquiz2.txtに出力 printf "%2s %2s %2s %2s %2s %2s %2s\n" "$su" "$mo" "$tu" "$we" "$th" "$fr" "$sa" >> ../results/quiz2.txt printf "%2s %2s %2s %2s %2s %2s %2s\n" "$su" "$mo" "$tu" "$we" "$th" "$fr" "$sa" #入力された月の最終日まで終わったらループ終了 done