How to increment variable under DOS?

前端 未结 9 1664
清酒与你
清酒与你 2021-02-06 21:36

I\'ve spent the past 3hrs trying to work this out but just couldn\'t find a solution. Here\'s my batch script:

if NOT Exist Counter.txt GOTO START
Type c:\\count         


        
9条回答
  •  名媛妹妹
    2021-02-06 22:05

    I built my answer thanks to previous contributors.

    Not having time for a custom counter.exe, I downloaded sed for FREEDOS.

    And then the batch code could be, emulating "wc -l" with the utility sed, something like this according to your loop (I just use it to increment through executions starting from "1" to n+1):

    Just remember to manually create a file "test.txt" with written on the first row

    0


    sed -n '$=' test.txt > counter.txt
    set /P Var=< counter.txt
    echo 0 >> test.txt
    

提交回复
热议问题