#!/bin/bash if [ $# -ne 1 ] then echo 引数を一つ入力してください exit fi #引数が1つでない場合スクリプトを終了する。 if [ $1 -lt 2016 ] then echo '2016年以降の年を指定してください。' #引数が2016より小さい場合、”2016年以降の年を指定してください。”と表示する。 else n=0 i=2016 a=20 b=16 #定数を定義する。 while [ $i -le $1 ] do #任意の西暦までの繰り返し c=$(( ($b-1) / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 13 + 1 ) / 5 )) g=$(( ($b-1) + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #1月に13日の金曜日があるかどうかの判定。あれば、nに1を足す。 #2月に13日の金曜日があるか判定 c=$(( ($b-1) / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 14 + 1 ) / 5 )) g=$(( ($b-1) + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #2月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 3 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #3月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 4 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #4月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 5 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #5月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 6 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #6月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 7 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #7月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 8 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #8月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 9 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #9月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 10 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #10月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 11 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #11月の判定。 c=$(( $b / 4 )) d=$(( $a / 4 )) e=$(( 2 * $a )) f=$(( 13 * ( 12 + 1 ) / 5 )) g=$(( $b + $c + $d - $e +$f + 13 )) h=$(( $g % 7 )) if [ $h = 6 ] then n=`expr $n + 1` else n=`expr $n` fi #12月の判定。 b=`expr $b + 1` i=`expr $i + 1` #bとiにそれぞれ1を足して、繰り返す。 done echo $n日 #合計日数の表示。 fi