many_miles
August 20th, 2008, 03:01 PM
I've read the FAQs about posting and I've a fairly good handle on bash programming.
I am trying to get the numerical value of "last month". Since this is August, the last month value I'm looking for is 7.
Obviously, I can just subtract one from "this month" as long as this month is not 1. If this month is one, last month is 12.
As you can see, I am using the date +%m command for obtaining the two digit month number.
To do that, I have this code
#!/bin/bash
# First find out what this month is...
THIS_MONTH_NUM=`date +%m`
if [ $THIS_MONTH_NUM -eq 1 ]; then
SRCH_MONTH_NUM=12
else
SRCH_MONTH_NUM=$((THIS_MONTH_NUM-1))
fi
But, on my Hardy Heron Ubuntu, because $THIS_MONTH_NUM contains 08, that produces:
./show_last_month: line 9: 08: value too great for base (error token is "08")
So, I figured I could force a string comparison by replacing line 6 with
if [ "$THIS_MONTH_NUM" == "01" ]; then
but, I still get the same error.
I've seen this other posting which I can use as a workaround
http://ubuntuforums.org/showthread.php?p=4206419
But, I am more curious as to why it's not a stringwise comparison...
I am trying to get the numerical value of "last month". Since this is August, the last month value I'm looking for is 7.
Obviously, I can just subtract one from "this month" as long as this month is not 1. If this month is one, last month is 12.
As you can see, I am using the date +%m command for obtaining the two digit month number.
To do that, I have this code
#!/bin/bash
# First find out what this month is...
THIS_MONTH_NUM=`date +%m`
if [ $THIS_MONTH_NUM -eq 1 ]; then
SRCH_MONTH_NUM=12
else
SRCH_MONTH_NUM=$((THIS_MONTH_NUM-1))
fi
But, on my Hardy Heron Ubuntu, because $THIS_MONTH_NUM contains 08, that produces:
./show_last_month: line 9: 08: value too great for base (error token is "08")
So, I figured I could force a string comparison by replacing line 6 with
if [ "$THIS_MONTH_NUM" == "01" ]; then
but, I still get the same error.
I've seen this other posting which I can use as a workaround
http://ubuntuforums.org/showthread.php?p=4206419
But, I am more curious as to why it's not a stringwise comparison...