Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: !Around Variable Name!

Reply
Thread Tools Display Modes

Re: !Around Variable Name!

 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      03-11-2009

"Alan" <> wrote in message
news:5aa34481-a361-4796-8a1e-...
> 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?


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      03-12-2009

"Alan" <> wrote in message
news:2557b37a-4355-4ffc-a72e-...
>> 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!.


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OU name to variable Murphy Scripting 6 11-08-2004 07:09 PM
OU name to variable Murphy Scripting 0 11-01-2004 01:00 PM
UO to variable Murphy Scripting 0 11-01-2004 12:59 PM
UO to variable Murphy Scripting 0 11-01-2004 12:54 PM
Variable Michelle Yu Scripting 2 07-27-2003 04:10 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59