You want something effectively like echo %count%+1
? No, this won't work. The only way to do math in cmd
is the set /a
command.
I personally won't touch my original variable but use a dummy var;
set /a xcount=count+1
echo %xcount%
(just a thing of personal preference).
What actually would work:
set /a count=5
cmd /c set /a x=count+1
cmd /c set /a x=count+1 & echo/ this is plus one
cmd /c "<nul set /p "x=%Count% plus one is " & set /a x=count+1 &echo/. Ready."
echo %count% is still 5
because the set
command is then done (in a new process) directly "on the command line" and set /a
shows the result when done on the command line (but doesn't show the result in a batch file).
Contra: It's quite easy to show just the number (first cmd...
line), but if you want to put some text "around", it quickly gets ugly (second line to append text, third line to put text around the number). And you open a new process. If you do it in a loop (as the variable name count
suggests), it may slow down your script considerably.