shell脚本写万年历

作者: SuperDing | 来源:发表于2016-09-10 19:24 被阅读0次

    题目要求:当手动输入年数、月数后显示当年、当月的第一天是星期几 同时打印万历表

    echo "Please input number of year:"
    read intPutYear
    let reyear=intPutYear

    echo "Please input number of mouth:"
    read intPutMouth
    let dd=intPutMouth
    //计算输入的年到1990年有多少天
    sumYear=0
    while ((1990<intPutYear))
    do
    if ((intPutYear%4==0&&intPutYear%100!=0))||((intPutYear%400==0))
    then
    let sumYear+=366
    else
    let sumYear+=365
    fi
    let intPutYear--
    done
    计算输入的月到这一年初的时间
    let mouth1=1
    let sumMouth=0 //计算输入的月到这一年初的时间
    let mouthday=0 //判断当前输入的月有多少天

    if ((dd==1)) //计算如果输入月份是一月的情况
    then
    let sumMouth=31
    let mouthday=31
    fi
    //计算输入的月份是大于一月小于等于12月的情况
    while ((mouth1<dd))
    do
    case $mouth1 in
    "1")
    let sumMouth+=31
    let mouthday=31
    ;;
    "2")
    if ((intPutYear%4==0&&intPutYear%100!=0))||((intPutYear%400==0))
    then
    let sumMouth+=28
    let mouthday=28
    else
    let sumMouth+=29
    let mouthday=29
    fi
    ;;
    "3")
    let sumMouth+=31
    let mouthday=31
    ;;
    "4")
    let sumMouth+=30
    let mouthday=30
    ;;
    "5")
    let sumMouth+=31
    let mouthday=31
    ;;
    "6")
    let sumMouth+=30
    let mouthday=30
    ;;
    "7")
    let sumMouth+=31
    let mouthday=31
    ;;
    "8")
    let sumMouth+=31
    let mouthday=31
    ;;
    "9")
    let sumMouth+=30
    let mouthday=30
    ;;
    "10")
    let sumMouth+=30
    let mouthday=30
    ;;
    "11")
    let sumMouth+=30
    let mouthday=30
    ;;
    "12")
    let sumMouth+=31
    let mouthday=31
    ;;
    *)
    echo "Wrong information"
    ;;
    esac
    let mouth1++
    done

    let sumDays=sumYear+sumMouth//计算输入的年 月距离1990年1月1号有多少天
    let valueDay=sumDays%7 //计算输入的年 月是这个月的星期几
    echo "${reyear}年${dd}月的第一天是星期${valueDay}"

    fun1() //输入万历表的 星期
    {
    for value1 in "$@"
    do
    printf "%s\t" "${value1}"
    done
    }
    week=( 日 一 二 三 四 五 六 )
    fun1 ${week[@]}
    printf "\n"

    blank=1 //输出空(当月万历表星期几之前的空)
    while ((blank<valueDay))
    do
    printf " \t"
    let blank++
    done

    let tim1=1 //输出当月万历表的当月天数排版
    while((time1<=mouthday))
    do
    printf "%s\t" "${time1}"
    //判断,当到达周六,开始换行。万历表格式(日 一 二 三 四 五 六)
    let data2=time1+blank
    if ((data2%7==0))
    then
    printf "\n"
    fi
    let time1++
    done
    printf "\n"

    相关文章

      网友评论

        本文标题:shell脚本写万年历

        本文链接:https://www.haomeiwen.com/subject/imoyettx.html