列出这个月的所有星期一 [英] List all the mondays of this month

查看:70
本文介绍了列出这个月的所有星期一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于bash和所有终端来说,我还是很陌生-我一直在纠缠着cal和date脚本,想知道是否仍然可以列出当前月份的所有星期一的日期.我的思考过程是通过cal命令进行的,列出了日期,甚至可能从该输入中删去一列.有可能吗?

I'm pretty new to bash and all the terminal in general - I've been messing around with cal and the date scripts wondering if there is anyway to list all the dates of monday of the current month . My thought process is going thru the cal command, listing out the dates and maybe cutting a column from that input. Is that possible ?

推荐答案

您可以使用 date 命令执行此操作.从一个月前开始打印10个星期一:

You can do it with date command. Print 10 mondays since month ago:

for x in $(seq 0 9)
do
    date -d "$x monday 5 week ago"
done

而grep仅在当前月份.完整命令: for $(seq 0 9)中的x;做;date -d"$ x 5周前的星期一";完成|grep $(日期+%b)

And grep only current month. Full command: for x in $(seq 0 9); do; date -d "$x monday 5 week ago"; done | grep $(date +%b)

输出:

Mon Jun  5 00:00:00 MSK 2017
Mon Jun 12 00:00:00 MSK 2017
Mon Jun 19 00:00:00 MSK 2017
Mon Jun 26 00:00:00 MSK 2017

这篇关于列出这个月的所有星期一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆