0

I'm not able to pull in correct partition value when the day of the month is before the 10th. Can someone advise the error in logic where I am assigning value to PARTITION?

NEW=`date +"%Y%m" --date="next month" | sed 's/ *//'`
OLD=`date +"%Y%m" --date="last month" | sed 's/ *//'`
PARTITION=`date --date="+2 month -$(($(date +"%d")-1)) days 00:00:00" +"%s"  | sed 's/ *//'`

The error I get is on the PARTITION declaration:

-bash: 08: value too great for base (error token is "08")
user3299633
  • 2,971
  • 3
  • 24
  • 38

2 Answers2

3

k314159's answer is correct. Here is an alternate answer: do not use leading zeros in date's output by specifying %-d instead of %d:

echo $(($(date +"%-d") - 1))
xhienne
  • 5,738
  • 1
  • 15
  • 34
2

The problem occurs in the expression $(($(date +"%d")-1)). The date command returns "08" and Bash (and other shells) treat numbers with a leading zero as octal.

To force decimal representation, precede the number with 10#.

So in your case, use $((10#$(date +"%d")-1)).

k314159
  • 5,051
  • 10
  • 32