#!/bin/bash # monthdays # calculates the number of days in a month # usage monthdays [mon] [year] # set the month and the year m=$1 y=$2 # 30 days hath September etc. case $m in 1|3|5|7|8|10|12) echo 31 ; exit ;; 4|6|9|11) echo 30 ; exit ;; *) ;; esac # except for month 2, which depends on whether the year is a leap year # Use yeardays to get the number of days in the year and return a value # accordingly. diy=`yeardays $y` case $diy in 365) echo 28 ; exit ;; 366) echo 29 ; exit ;; esac