this question has answer here:
i trying generate startdate in format yyyymmdd such date 1st day of third last month. example, current month july (07), need start date 1st day of april (04) - 20150401.
in order achieve in bash, used following command:
startdate=$(date -d "-3 month -$(($(date +%d)-1)) days" +"%y%m%d") however, giving me following error:
line 93: 09: value great base (error token "09") i not want change format of startdate variable. single digit months (1-9), format should have leading 0 infront of month number in yyyymmdd format.
is there missing?
thanks in advance!
bash seeing 09 , trying treat octal number fails.
you can prefix date value 10# force base. see second-to-last paragraph of shell arithmetic.
startdate=$(date -d "-3 month -$((10#$(date +%d)-1)) days" +"%y%m%d")
Comments
Post a Comment