When entered manually into the commnand prompt, the following sequence works as desired:
>set /a r=3%2
1
>echo %r%
1
However, when launched from batchh file, it doesn't, as %2 clearly has a different meaning.
>set /a r=3%2
>echo %r%
3
How do I make the batch file do what I did in the first example, claculating the remainder? The system in question is XP.
%%i is simply the loop variable. This is explained in the documentation for the for command, which you can get by typing for /? at the command prompt. The fact that a double percent sign is used in a batch file is discussed in these links: What is the difference between % and %% in a cmd file?
Pressing "y" would use the goto command and go back to start and rerun the batch file. Pressing any other key would exit the batch file.
A batch file is a script file that stores commands to be executed in a serial order. It helps automate routine tasks without requiring user input or intervention. Some common applications of batch files include loading programs, running multiple processes or performing repetitive actions in a sequence in the system.
use this syntax in batch-files:
set /a "r=3 %% 2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With