bat script problem with "tokens"

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

We use a .bat file script to compile from clearcase and
zip up our software everynight. The first thing the
script does is use the DATE commadn to construct a date
tag for the build:

set MYDATE=%DATE%

set MON_NUM=%MYDATE:~4,2%
set DAY_NUM=%MYDATE:~7,2%
set YEAR=%MYDATE:~10,4%

for /f "tokens=%MON_NUM%" %%a in (
"JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC") do
set MON_NAME=%%a

set t=DEV_%YEAR%%MON_NAME%%DAY_NUM%


Just recently we found the builds being named WITHOUT the
month in them. After some investigation I determined that
the "for" line was failing when the MON_NUM was either 08
or 09... it works for every other one though.

I put in this hack:

IF "%MON_NUM%"=="08" SET MON_NUM=8
IF "%MON_NUM%"=="09" SET MON_NUM=9

which works around the problem. Apparently, it has no
problem with just 8 and 9 only with 08 and 09.

I was hoping to gain some insight into this strange
quirk... any info would be greatly appreciated.
 
I'm pretty sure it's because the 'for' command is interpreting the 08 or 09
as base 8 (octal). As for the other months, it doesn't matter, since it's
either obvious (10, 11, 12) or it makes no difference (01-07). This
conforms to (at least) the rules for numbers in C/C++.

You're going to have to strip off the leading 0 somehow...
 
I thought it might be somethign like that but I don't
understand on that basis why 08 doesn't work but 8 does?
What causes the 08 to be interpreted as octal and not 8..
or 18 for that matter (which I also played with).
 
As I said before, that's the C++ standard...if you want something to be
interpreted as:

- octal, then prefix the value with 0
- hexadecimal, then prefix the value with 0x

Everything else is decimal.
 
Back
Top