小编Lee*_*hie的帖子

列出在一周的同一天结束的月份

这是一个任务。我有以下代码:

#! /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)

unix bash

2
推荐指数
1
解决办法
119
查看次数

标签 统计

bash ×1

unix ×1