【发布时间】:2010-10-16 21:24:39
【问题描述】:
我想在 bash 中进行一些日历操作 - 具体来说,我想找出给定月份的最后日期(包括闰年,并且为查找准备表格对我来说不是一个有效的解决方案)。
假设我有以下代码:
$year=2009
$start_month=2
$end_month=10
for $month in $(seq $start_month $end_month); do
echo "Last date of "$(date +"%B" -d "${year}-${month}-01")" is: " ???
done
我不知道如何做这样的事情。我虽然 date -d 会像 POSIX mktime 一样工作,并将无效日期折叠为其有效等价物,所以我可以说类似 date -d "2009-03-00" 并得到“2009-02-28”,但没有这样的运气。
有没有办法只使用标准 GNU 环境中的 bash 提供的功能?
【问题讨论】:
标签: linux bash shell command-line