Home All Groups Group Topic Archive Search About
Author
11 Mar 2009 7:24 PM
Alan
What does "!" around a variable name, as in

if !LINECNT!==TEST

mean?

                            Thanks, Alan

Author
11 Mar 2009 8:46 PM
Pegasus [MVP]
"Alan" <jalantho***@verizon.net> wrote in message
news:5aa34481-a361-4796-8a1e-0dd24593907d@13g2000yql.googlegroups.com...
>   What does "!" around a variable name, as in
>
> if !LINECNT!==TEST
>
> mean?
>
>                            Thanks, Alan

Try these batch files:
@echo off
set Number=
for /L %%a in (1,1,10) do (
  set Number=%%a
  echo Number=%Number%
)

@echo off
SetLocal EnableDelayedExpansion
set Number=
for /L %%a in (1,1,10) do (
  set Number=%%a
  echo Number=!Number!
)

See the difference?
Are all your drivers up to date? click for free checkup

Author
12 Mar 2009 12:32 AM
Alan
> See the difference?

Yes.  But why?
Author
12 Mar 2009 9:10 AM
Pegasus [MVP]
"Alan" <jalantho***@verizon.net> wrote in message
news:2557b37a-4355-4ffc-a72e-99510ab6069b@w34g2000yqm.googlegroups.com...
>> See the difference?
>
> Yes.  But why?
>

In this batch file

@echo off
set Number=
for /L %%a in (1,1,10) do (
  set Number=%%a
  echo Number=%Number%
)

the following lines of code

for /L %%a in (1,1,10) do (
  set Number=%%a
  echo Number=%Number%
)

are treated as one single line of code. The command processor reads this
"single" line, then resolves its variables. Since the variable "%Number% is
set to "nothing" at the beginning, it remains at "nothing". To force a
rescan, you must do two things:
- You must enable "delayed expansion"
- You must replace the %Number% with !Number!.

Bookmark and Share

Post Thread options