Skip to main content

Batch Script Assignment Operators

Assignment Operators

Batch Script language provides assignment operators.

The following table lists the available assignment operators.

OperatorDescriptionExample
+=This adds right operand to the left operand and assigns the result to left operandset /A a=5 a+=3 Output will be 8
-=This subtracts the right operand from the left operand and assigns the result to the left operandset /A a=5 a-=3 Output will be 2
*=This multiplies the right operand with the left operand and assigns the result to the left operandset /A a=5 a*=3 Output will be 15
/=This divides the left operand with the right operand and assigns the result to the left operandset /A a=6 a/=3 Output will be 2
%=This takes modulus using two operands and assigns the result to the left operandset /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
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%
10
5
25
5
5