这是一个任务。我有以下代码:
#! /bin/bash
y=$1
if [ -z $1 ] # if year is not specified use the current year
then y=(`date +%Y`)
fi
for m in {1..12}; do
if [ $m -eq 12 ] # december exception
then echo $(date -d $m/1/$y +%b) - $(date -d "$(($m%12+1))/1/$y" +%A)
break
fi
echo $(date -d $m/1/$y +%b) - $(date -d "$(($m%12+1))/1/$y - 1 days" +%A) # print the last day of the week for the month
done
Run Code Online (Sandbox Code Playgroud)
它列出了每个月一周的最后一天:
Jan - Monday
Feb …Run Code Online (Sandbox Code Playgroud)