題目要求:當(dāng)手動輸入年數(shù)轻绞、月數(shù)后顯示當(dāng)年腰耙、當(dāng)月的第一天是星期幾 同時打印萬歷表
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 //判斷當(dāng)前輸入的月有多少天
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 //輸出空(當(dāng)月萬歷表星期幾之前的空)
while ((blank<valueDay))
do
printf " \t"
let blank++
done
let tim1=1 //輸出當(dāng)月萬歷表的當(dāng)月天數(shù)排版
while((time1<=mouthday))
do
printf "%s\t" "${time1}"
//判斷,當(dāng)?shù)竭_(dá)周六铲球,開始換行。萬歷表格式(日 一 二 三 四 五 六)
let data2=time1+blank
if ((data2%7==0))
then
printf "\n"
fi
let time1++
done
printf "\n"