Batch for loop problem in XP

Microsoft Windows xp professional w/serv...
July 18, 2010 at 23:04:45
Specs: Windows XP
set MM=08
for /f "tokens=%MM%" %%i in ("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do (set MMM=%%i)
echo %MMM%

Above batch doesn't run properly for 08 and 09 and gives error 8" was unexpected at this time., it does work if value is 07 or 11 or any other.

Any ideas guys?

Thanks in advance/

See More: Batch for loop problem in XP

Report •

July 19, 2010 at 02:20:52
Cmd.exe treats numbers beginning with 0 (zero) as Octal so 08 and 09 are invalid. Set /a 2*08 will produce the error message "Invalid number. Numeric constants are either decimal (17), hexadecimal (0x11), or octal (021)" For just gives the "unexpected" error message.

Report •

July 19, 2010 at 02:29:23
Thanks Wahine.

I found out a way to solve this.

added below line before for loop, it will give me modulo remainder without 0 in the start.

set /a %MM%=1000%MM% %% 1000

Thanks again

Report •

July 19, 2010 at 11:47:21
I should have indicated that only some command shell commands treat numbers with a leading zero as Octal, IF is an exception so you could have used an IF command as well.

Your solution is probably as good as any.

Report •

Related Solutions

Ask Question