shell 求某年的某月有多少天

cal_days_in_month()
{
        n_year=`expr $1 + 0`
        n_month=`expr $2 + 0`
        n_day=0;
        case $n_month in 1|3|5|7|8|10|12)
                n_day=31;;
        4|6|9|11)
                n_day=30;;
        2)
                if [ `expr $n_year % 4` -eq 0 ];then
                        if [ `expr $n_year % 400` -eq 0 ];then
                                n_day=29;
                        elif [ `expr $n_year % 100` -eq 0 ];then
                                n_day=28;
                        else
                                n_day=29;
                        fi
                else
                        n_day=28;
                fi
        ;;
        esac
        echo ${n_day};
}

你可能感兴趣的:(Linux)