linux shell系列10 判断某个月中的星期六和星期天

#!/bin/bash
read -p "请输入月份:" month #输入要查找的月份

mon=`date -d "0 month ago" +%m` #计算本月
s=${mon:1:2}

if [ $month -lt 10 ];then
mc=$[ $month-$s ] #计算本月和输入月份相差几个月
f=`date +"%Y0${month}01"` #输入月的第一天
elif [ $month -gt 9 ];then
mc=$[ $month-$s ] #计算本月和输入月份相差几个月
f=`date +"%Y${month}01"` #输入月的第一天
fi


l=`date -d"$(date -d"$[1+$mc] month" +"%Y%m01") -1 day" +"%Y%m%d"` #输入月的最后一天
datef=${f:7:8}
datel=${l:6:8}
for i in $(seq 0 $[$datel-1])
do
temp=`date -d"$f $i day" +"%Y%m%d"`
temp_week=`date -d $temp +%w`
if [ $temp_week = 6 ];then
echo "星期六 $temp"
elif [ $temp_week = 0 ];then
echo "星期天 $temp"
fi
done

  

posted @ 2018-08-17 11:25  划得戳  阅读(1074)  评论(0编辑  收藏  举报