Home > front end >  How to print value after enabledelayedexpansion
How to print value after enabledelayedexpansion

Time:12-10

Setting a variable in a "setlocal enabledelayedexpansion" works with

set HASGCC=0    
for /f "delims=" %%i in (...) do (
        setlocal enabledelayedexpansion
            set HASGCC=1
        endlocal
    )

but sadly a echo after doesn't result in the correct value (always 0).

   echo Finished %HASGCC%

Afterwards

if !HASGCC! == 0  >>"%PREFS_F...

is evaluated correct.

How to print correct value.

echo Finished !HASGCC!

results in

Finished !HASGCC!

CodePudding user response:

Solved it by removing

setlocal enabledelayedexpansion

but don't know why.

CodePudding user response:

setlocal with or without EnableDelayedExpansion creates a new scope for variables.
It makes a copy of all variables and then all changes are made to these copies.
An endlocal leaves this scope and discard the copy and all changes are dsicarded.

For some variable manipulations you have to enable delayed expansion for some it's better to use disabled delayed expansion, but the only way to switch between them is to use setlocal.

But in your case it seems, that you don't need it at all.

  • Related