检查 shell 参数是否是一个月的最后一天

check if shell argument is last day of month

我想检查命令行中传递的参数是否是一个月的最后一天,如下所示: ./check_date.sh 20210731

如果 20210731 是月的最后一天 echo "月的最后一天" 否则回显“没有一个月的最后一天”

mydate=""
#i found this code in Whosebug thread but do not now if can take my argument to check weather is the last day or month or not

if [[ $(date -d "+1 day" +%m) != $(date +%m) ]]
then
    echo "Today is the last day of the month"
else
    echo "Today is NOT the last day of the month"
fi


谢谢

只需检查 1 day 是否已添加到您的日期 </code> 中,表示为一个月中的第几天 <code>+%d,计算结果为 01:

if [[ $(date -d " + 1 day" +%d) == 01 ]]
then echo " is the last day of month"
else echo " is NOT the last day of month"
fi