我想檢查命令列中傳遞的引數是否是月份的最后一天,如下所示:./check_date.sh 20210731
如果 20210731 是本月的最后一天 echo "last day of month" else echo "no the last day of month"
mydate="$1"
#i found this code in stackoverflow 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
謝謝
uj5u.com熱心網友回復:
只需檢查是否1 day添加到您的日期$1,表示為月份中的某天 %d,計算結果為01:
if [[ $(date -d "$1 1 day" %d) == 01 ]]
then echo "$1 is the last day of month"
else echo "$1 is NOT the last day of month"
fi
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428515.html
下一篇:如何從grep獲得有意義的輸出?
