Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This one could turn out as the dumbest question ever, as I am probably missing out the obvious. Anyway, here it is: Can you evaluate expressions in a batch script. For example, I want to add two numbers and print the result:

echo 4+2

This will just print "4+2", not "6". Maybe I am taking batch scripting on windows a little bit too far...


share|improve this question
up vote 5 down vote accepted

This way:

Set /a 4+2

Or to store it in a variable for later:

Set /a foo = 4+2
echo %foo%

And to answer your last line, there is a good chance that you may be pushing batch a little further than intended. The Windows Script host is available on your machine and would allow VBScript or JScript. Also if you are going to learn something new anyway I would highly suggest using Powershell instead.

share|improve this answer
that's echo %foo% – Bob Aug 28 '09 at 15:42
Oops...fixed. Thanks. – EBGreen Aug 28 '09 at 15:45
set Result=0

echo start %Result%

echo Adding 4 and 2
set /a Result= 4+2

echo finish %result%

pause >nul
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.