0

I am trying to get the first day of the previous month using shell script using the below command in the format 2017-05-01

Firstday=date -d "-1 month -$(($(date +%d)-1)) days" +"%Y-%m-%d"

But it is throwing the below error.

value too great for base (error token is "09").

Can anyone help please?

dijin
  • 61
  • 6
  • the issue is related to https://stackoverflow.com/questions/21049822/bash-error-value-too-great-for-base-error-token-is-09 But not able to fit in to my requirement. – dijin Jun 09 '17 at 08:58
  • START_DATE=`date -d "-1 month -$(expr $(date +%d) - 1) days" +"%Y-%m-%d"` Got It :) – dijin Jun 09 '17 at 09:30

1 Answers1

0

You can use %e to pad the day with a space, rather than a zero:

firstday=$(date -d "-1 month -$(( $(date +%e) - 1 )) days")

The leading space has no effect on the expansion.

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141