#!/bin/bash #引数が一つではない場合の処理 if [ $# -ne 1 ]; then echo 引数を一つ入力してください exit fi #引数が2016より小さい場合の処理 if [ $1 -lt 2016 ] then echo 2016年以降の年を指定してください else #定数の定義 n=0 i=2016 a=20 b=16 #引数の年までの繰り返し while [ $i -le $1 ] do #1月に13日の金曜日があるか判定 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 #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 #3月に13日の金曜日があるか判定 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 #4月に13日の金曜日があるか判定 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 #5月に13日の金曜日があるか判定 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 #6月に13日の金曜日があるか判定 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 #7月に13日の金曜日があるか判定 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 #8月に13日の金曜日があるか判定 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 #9月に13日の金曜日があるか判定 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 #10月に13日の金曜日があるか判定 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 #11月に13日の金曜日があるか判定 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 #12月に13日の金曜日があるか判定 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 b=`expr $b + 1` i=`expr $i + 1` done #合計日数の表示 echo $n日 fi