PARTIES; execution of commands inside variables using for

so I have several vars stored in a text file in a batch file

(
set /p var1=
set /p var2=
set /p var3=
)<oi.txt

and they are an if statement.

if I were to run% var1%, it would execute the if statement, however, when I ran

for /l %%i in (1,1,3) do !var%%i!

(in setlocal enabledelayedexpansion) it launches if, however returns

`if` is not recognized as an internal or external command
`if` is not recognized as an internal or external command
`if` is not recognized as an internal or external command

Is this oversight of Microsoft? or maybe something that fixes another price error without having this option?

* edit this has nothing to do with the for command using! var% number%! with var1 having inside an if statement returns the same problem. (also, im 100% sure that the if statement inside var is correct, why not recognize it even if it was incorrect?)

+4
source share
1

, , . %macro%. !macro! - .

cmd.exe( ) - . , .

, jeb, , IF FOR.

IF, FOR , 2. 5. , IF FOR , .

. FOR IF "macro", %macro%.

, FOR IF.

IF:

@echo off
setlocal enableDelayedExpansion
set "ifFlag=/I"

:: This works
if %ifFlag% a==A echo match

:: This does not work
if !ifFlag! a==A echo match

:

@echo off
setlocal enableDelayedExpansion
set "forOptions=delims=: tokens=1,2"

:: This works
for /f "%forOptions%" %%A in ("1:2") do echo A=%%A  B=%%B

:: This does NOT works
for /f "!forOptions!" %%A in ("1:2") do echo A=%%A  B=%%B
+2

Source: https://habr.com/ru/post/1681341/


All Articles