我正试着根据日期来确定这个月。到现在为止,它在命令下工作得很好-
cur_mon=`date --date="$report_date" '+%m' -d 'now'`
cur_year=`date --date="$report_date" '+%y' -d 'now'`
echo cur_mon and cur_year =${cur_mon} and ${cur_year}$report_date现在是2014年9月30日。
它给了我输出- cur_mon和cur_year =10和14
如果有人知道原因以及解决办法,请告诉我。此外,这也会在一年中造成问题。如果日期是2014年12月31日。
发布于 2014-10-01 19:18:17
我想我看到你的问题了,你在试图两次描述你的约会对象。一次用--date="$report_date“,第二次用-d。只有后者才有效。这就是为什么你看到10而不是9。
发布于 2014-10-01 19:19:13
试试awk '{print $2}' <(date),它应该在日期的输出中选择由空格分隔的第二个元素,这是名义上的月份。
https://stackoverflow.com/questions/26148492
复制相似问题