Type casting problem

hi guys,

i m new to shell script..

i dont know how to type cast string into integers and i mention my problem below..

date="21091988"
month=$((${date:2:2})) # extract the month from previous date variable
temp=$(($month*23))

when i am trying to calculate the temp value i got the following error..
09: value too great for base (error token is "09")
*23: syntax error: operand expected (error token is "*23")

i tried with following declaration,
declare -i month

bt above also not works....

i dont know where it gets wrong...

when i m assigning month value less than 8... it works nicely yar.....

i think it s something related to octane.... bt i dont know the extactly dears...

please help me....:wall::wall::wall::wall::wall::wall::wall:

To overcome .. :slight_smile:

month=$((10#${dat:2:2}))
month=${date:2:2}
((temp=${month#${month%%[1-9]*}}*23))

Here's a work-around. I've added a line to remove zeros from the beginning of $month, if it exists.

date="21091988"
month=${date:2:2} # This much is sufficient. Double round braces are not required.
month=${month/#0/}
temp=$(($month * 23))

Dear All,

Its working yar... thanks to all dears...... its really interesting and i wanna know some ideas..

month=$((10#${dat:2:2}))

y we need to add "10#" and how this work dear.. please give idea yar......

is that base 10.... converting from base 8 to base 10......

((temp=${month#${month%%[1-9]*}}*23))

hey how this work... please give idea dear....

$((10#${dat:2:2})) : converting the string to decimal digits
${month%%[1-9]} stripping from the first non-zero character until the end of the string, that is, just remain the leading sequentially zeros
${month#${month%%[1-9]
}} : stripping the leading sequentially zeros!