Code is self explanatory. I have tried the commands in the commented lines with equal results. Last lines are test of incremental assignment and evidence enabledelayedexpansion works. The fault must lie within the for loop.
@echo off
setlocal EnableDelayedExpansion
set count_k=5
for /l %%a in (1,1,5) do (
rem set a/ count_k+=1
rem set a/ "count_k+=1"
set a/ count_k=count_k+1
echo This is count_k per %count_k%
echo This is count_k exc !count_k!
)
echo After loop this is count_k %count_k%
set _var=first
set _var=second & echo %_var% !_var!
set count = 0
(
set /a count+=1
echo %count% fails
echo !count! works
)
This is the output of the above batch file:
This is count_k per 5
This is count_k exc 5
This is count_k per 5
This is count_k exc 5
This is count_k per 5
This is count_k exc 5
This is count_k per 5
This is count_k exc 5
This is count_k per 5
This is count_k exc 5
After loop this is count_k 5
first second
fails
1 works