Batch Script Assignment Operators
Assignment Operators
Batch Script language provides assignment operators.
The following table lists the available assignment operators.
| Operator | Description | Example |
|---|---|---|
= | Assigns the value of the right operand to the left operand | set /A a=5 Output will be 5 |
+= | Adds the right operand to the left operand and assigns the result to the left operand | set /A a=5 a+=3 Output will be 8 |
-= | Subtracts the right operand from the left operand and assigns the result to the left operand | set /A a=5 a-=3 Output will be 2 |
*= | Multiplies the right operand with the left operand and assigns the result to the left operand | set /A a=5 a*=3 Output will be 15 |
/= | Divides the left operand by the right operand and assigns the result to the left operand | set /A a=6 a/=3 Output will be 2 |
%= | Takes modulus using two operands and assigns the result to the left operand | set /A a=5 a%=3 Output will be 2 |
Example
The following code snippet shows how the various operators can be used.
Example of Assignment Operators
@echo off
set /A a=5
echo %a%
set /A a+=5
echo %a%
set /A a-=5
echo %a%
set /A a*=5
echo %a%
set /A a/=5
echo %a%
set /A a%=5
echo %a%
5
10
5
25
5
5