How can I get the 1st and last date of the previous month in a Bash script?

后端 未结 7 1639
小蘑菇
小蘑菇 2020-12-31 03:52

I have scheduled a Bash script to run on the 1st of the month but I need to create 2 variables in it with the 1st and last date of the previous month, whatever those may be.

相关标签:
7条回答
  • 2020-12-31 04:35

    You can try following date commands regardless of the day you are executing them to get first and last day of previous month

    Firstday=`date -d "-1 month -$(($(date +%d)-1)) days"`
    Lastday=`date -d "-$(date +%d) days"`
    
    0 讨论(0)
提交回复
热议问题