shell版本的万年历

刚知道代码区块的用法《pre》和《/pre》夹住想打的内容纪念一下


echo "please write year and month by twice!"
read y
read m
if [[ $(($y%4)) -eq 0 && $(($y%100)) != 0 ]] || [ $(($y%400)) == 0 ]
then
ry=1
else
ry=0
fi
let fd=5*${y}/4+${y}%4-${y}/100+${y}/400
echo " ============================"
echo -e " Year${y} Month${m}\n Sun Mon Tue Wed Thr Fri Sat"
days=(31 28 31 30 31 30 31 31 30 31 30 31)
if [ ${ry} -eq 1 ]
then
days[1]=28
fi
i=0 d=0
while [ ${i} -lt $((${m}-1)) ]
do
let d=${d}+${days[${i}]}
let i++
done
fdy=$(((${d}+${fd})%7))
day=1
i=1
while [ $i -le $fdy ]
do
printf " "
let i++
done
while [ ${day} -le ${days[$((${m}-1))]} ]
do
printf "%4d" "${day}"
let ca=$day+$fdy
cb=$(($ca%7))
if [ $cb -eq 0 ]
then
printf "\n"
fi
let day++
done
printf "\n"
echo " ============================"

你可能感兴趣的:(shell版本的万年历)