Page 1 of 1

error on for /f in the block

Posted: 01 Nov 2022 09:00
by einstein1969
Hello,

I need help with a for /f

if I run this code, the for /f gives me an error

Code: Select all

@echo off & setlocal enableDelayedExpansion

>"%TMP%\env.txt" set

set /a nl=10
(
for /f "skip=!nl! eol== delims==" %%V in (%TMP%\env.txt) do set "%%~V="
)

Code: Select all

!nl! eol== delims==" non atteso.
the for is inside a block, can someone explain to me how to solve it and why it don't works?

Re: error on for /f in the block

Posted: 01 Nov 2022 10:10
by miskox
If I replace

Code: Select all

!nl!
with

Code: Select all

%nl%
it works.

Why? Maybe % should not be replaced by ! (%%a is not replaced by !!a for example) in the command itself.

Saso

Re: error on for /f in the block

Posted: 01 Nov 2022 13:57
by aGerman
If you really need the delayed expansion of n1 then your best bet might be to run the loop in a subroutine. Another approach could be processing the output of MORE +!n1! "filename".

Steffen

Re: error on for /f in the block

Posted: 02 Nov 2022 05:46
by einstein1969
thanks

i use "more +!nl!" is more efficient