why wont 08 and 09 display? BATfile

Dell PRECISION
February 16, 2009 at 08:41:10
Specs: win xp 5.1.2600, 3mhz/2 gig
Hi all.
Here is a juicy one for you.

This code fetches a range from the users input and returns the values into 'newfile.txt'
It works fine on all other numbers, but wont return '08' or '09'. (ANYONE KNOW WHY?!!!)
you can extend the range if you so wish, but I only need to dd a few as an example.
05
06
07
08
09
10
11
12
13
14
15

the code is:

@echo off
setlocal enabledelayedexpansion
set /p min=set min criteria
set /p max=set max criteria
for /f "tokens=* delims=" %%a in (range.txt) do (
if %%a geq !min! if %%a leq !max! echo %%a>> newfile.txt
)


See More: why wont 08 and 09 display? BATfile

Report •


#1
February 16, 2009 at 08:45:22
Sorry, I should be more clear. When I did my previous searches I typed a range of say 4 to 12... and it wouldnt return 08 or 09.

But I have since typed the range 05 to 12 and it returns 08 and 09.

However if I type a range of 3 to 7 it returns 03, 04, 05, 06 and 07.

I cant figure out why.
Thanks again.


Report •

#2
February 16, 2009 at 09:28:51
@echo off
setlocal enabledelayedexpansion
set /p min=set min criteria 
set /p max=set max criteria 
set /a iMin=1%min%-100
set /a iMax=1%max%-100
for /f "tokens=* delims=" %%a in (range.txt) do (
if %%a geq !iMin! if %%a leq !iMax! echo %%a>> newfile.txt
)

not tested. i think because 08 and 09 is invalid number. try typing set/a 08 in command prompt, it wont work. set/a 0x08 work, however, value is treated as hex.
to overcome it, use set/a 108-100.

the same applies if your text file contain 08 and 09. convert it to number.


Report •

#3
February 16, 2009 at 09:34:41
lee123abc: (ANYONE KNOW WHY?!!!)
E:\>set /?

. . . . . .

If you use any of the logical or modulus operators, you will need to enclose the expression string in quotes. Any non-numeric strings in the expression are treated as environment variable names whose values are converted to numbers before using them. If an environment variable name is specified but is not defined in the current environment, then a value of zero is used. This allows you to do arithmetic with environment variable values without having to type all those % signs to get their values. If SET /A is executed from the command line outside of a command script, then it displays the final value of the expression. The assignment operator requires an environment variable name to the left of the assignment operator. Numeric values are decimal numbers, unless prefixed by 0x for hexadecimal numbers, and 0 for octal numbers. So 0x12 is the same as 18 is the same as 022. Please note that the octal notation can be confusing: 08 and 09 are not valid numbers because 8 and 9 are not valid octal digits.

I was going to use the <pre> tags, but you can't bold <pre> text in this forum anymore.


Report •

Related Solutions

#4
February 16, 2009 at 09:52:54
thanks guys, that certainly explains it!!!

I will work it into my script now!!!
Cheers


Report •

#5
February 16, 2009 at 16:38:11
Razor: this problem is caused by the IF command behaving rather like SET /A, but this is undocumented.

E.g. if 010 equ 8 echo IF supports octal!


Report •

#6
February 16, 2009 at 19:59:14
Klint,

The == treats it as a literal:

if 010==8 echo IF supports octal!

Razor2.3,

Thanks for the info.

lee123,

If you want to put out a continous sequence you can do this:

===========================================
@echo off & setLocal EnableDelayedExpansion

set /p min=min
set /p max=max

for /L %%a in (!min! 1 !max!) do (
echo %%a
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#7
February 17, 2009 at 05:58:20
M2, Thanks... I actually forgot all about the for /L loop!

Thanks for all answers guys.


Report •

#8
February 17, 2009 at 06:03:57
Once again, I answered to hastily.

Mechanix, I actually need the range from a list (another file). With the for /L I cant specify the other file, which is why I used for /f "tokens=* delims=" %%a in (range.txt) do ........

It is called range.txt

Any suggestions there?


Report •


Ask Question