Linux Bash Scripting Again....
Discussion
Bit stuck with a small problem:
I pass a date into my shell script as say 20040901 - 1st Sept 2004 - as STARTDATE
Then
declare -i STARTYEAR="${STARTDATE:0:4}"
declare -i STARTMONTH="${STARTDATE:4:2}"
declare -i STARTDAY="${STARTDATE:6:2}"
trouble is STARTMONTH gets forced into base 8 due to the leading zero on '09' and then unsurprisingly gives a value too large for base error.
Is their a quick easy way to ensure I get a decimal value for '08' and '09'? Similar problem occurs with some of the day values too...
many thanks
Ex
I pass a date into my shell script as say 20040901 - 1st Sept 2004 - as STARTDATE
Then
declare -i STARTYEAR="${STARTDATE:0:4}"
declare -i STARTMONTH="${STARTDATE:4:2}"
declare -i STARTDAY="${STARTDATE:6:2}"
trouble is STARTMONTH gets forced into base 8 due to the leading zero on '09' and then unsurprisingly gives a value too large for base error.
Is their a quick easy way to ensure I get a decimal value for '08' and '09'? Similar problem occurs with some of the day values too...
many thanks
Ex
TheExcession said:Ex, maybe I'm barking up the wrong tree, but are you sure about base 8?
Bit stuck with a small problem:
I pass a date into my shell script as say 20040901 - 1st Sept 2004 - as STARTDATE
Then
declare -i STARTYEAR="${STARTDATE:0:4}"
declare -i STARTMONTH="${STARTDATE:4:2}"
declare -i STARTDAY="${STARTDATE:6:2}"
trouble is STARTMONTH gets forced into base 8 due to the leading zero on '09' and then unsurprisingly gives a value too large for base error.
Is their a quick easy way to ensure I get a decimal value for '08' and '09'? Similar problem occurs with some of the day values too...
many thanks
Ex
Its just that 9 in base 8 is 11?
Greg
GregE240 said:
TheExcession said:
Bit stuck with a small problem:
I pass a date into my shell script as say 20040901 - 1st Sept 2004 - as STARTDATE
Then
declare -i STARTYEAR="${STARTDATE:0:4}"
declare -i STARTMONTH="${STARTDATE:4:2}"
declare -i STARTDAY="${STARTDATE:6:2}"
trouble is STARTMONTH gets forced into base 8 due to the leading zero on '09' and then unsurprisingly gives
a value too large for base error.
Is their a quick easy way to ensure I get a decimal value for '08' and '09'? Similar problem occurs with some of the day values too...
many thanks
Ex
Ex, maybe I'm barking up the wrong tree, but are you sure about base 8?
Its just that 9 in base 8 is 11?
Greg
true base 8 goes:
0,1,2,3,4,5,6,7,10,11,12,13,14,15,16,17,20,21....
but when bash sees a leading zero on a value and assigns it to a script variable the leading zero is interepetted as being an instruction to force into base 8 - which throws an error - I need to force it into base 10 -
or write something to drop the leading zero before doing the assignment.
Just need sumfin quick and simple and not sure what to do.
thanks
Ex
>> Edited by TheExcession on Thursday 28th October 10:30
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


