Evaluating expressions in windows batch script Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Come Celebrate our 10 Year Anniversary!Adding numbers stored in variables in windows batch scriptRunning a windows batch script in a separate processbatch script to retrieve zero byte filesNeed leading zero for batch script using %time% variablebatch file infinite loop when parsing fileIn a shell script, perform different actions depending on the file on a another server (web accessible)How to sleep in a batch file?Batch script terminates too soonBatch script to export info from Active Directory (name, phone numbers, location, etc) into a csv fileBatch script errorlevel issue with registry key
Does the set of sets which are elements of every set exist?
Identify story/novel: Tribe on colonized planet, not aware of this. "Taboo," altitude sickness, robot guardian (60s? Young Adult?)
Does Feeblemind produce an ongoing magical effect that can be dispelled?
What if Force was not Mass times Acceleration?
Are these square matrices always diagonalisable?
The art of proof summarizing. Are there known rules, or is it a purely common sense matter?
How to not starve gigantic beasts
Could moose/elk survive in the Amazon forest?
Where did Arya get these scars?
Password Generator in batch
Israeli soda type drink
"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?
Why did Israel vote against lifting the American embargo on Cuba?
Why does the Cisco show run command not show the full version, while the show version command does?
Need of separate security plugins for both root and subfolder sites Wordpress?
Married in secret, can marital status in passport be changed at a later date?
Check if a string is entirely made of the same substring
Map material from china not allowed to leave the country
How do I check if a string is entirely made of the same substring?
Additive group of local rings
All ASCII characters with a given bit count
What's parked in Mil Moscow helicopter plant?
How to open locks without disable device?
What is "leading note" and what does it mean to "raise a note"?
Evaluating expressions in windows batch script
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Come Celebrate our 10 Year Anniversary!Adding numbers stored in variables in windows batch scriptRunning a windows batch script in a separate processbatch script to retrieve zero byte filesNeed leading zero for batch script using %time% variablebatch file infinite loop when parsing fileIn a shell script, perform different actions depending on the file on a another server (web accessible)How to sleep in a batch file?Batch script terminates too soonBatch script to export info from Active Directory (name, phone numbers, location, etc) into a csv fileBatch script errorlevel issue with registry key
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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...
Thanks!
windows scripting batch
add a comment |
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...
Thanks!
windows scripting batch
add a comment |
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...
Thanks!
windows scripting batch
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...
Thanks!
windows scripting batch
windows scripting batch
asked Aug 28 '09 at 15:27
raoulssonraoulsson
1,86862729
1,86862729
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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.
that's echo %foo%
– Bob
Aug 28 '09 at 15:42
add a comment |
set Result=0
echo start %Result%
echo Adding 4 and 2
set /a Result= 4+2
echo finish %result%
pause >nul
add a comment |
If you have bash/perl installed (eg. cygwin), just call them to do the math:
@for /f "delims=" %%a in ('perl -e "print(%*)"' ) do @set RESULT=%%a
@echo %RESULT%
@for /f "delims=" %%a in ('bash -c "echo $((%*))"' ) do @set RESULT=%%a
@echo %RESULT%
Sample result:
c:> script.cmd 2**10/3
341.333333333333
341
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f60039%2fevaluating-expressions-in-windows-batch-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
that's echo %foo%
– Bob
Aug 28 '09 at 15:42
add a comment |
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.
that's echo %foo%
– Bob
Aug 28 '09 at 15:42
add a comment |
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.
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.
edited Aug 28 '09 at 15:45
answered Aug 28 '09 at 15:32
EBGreenEBGreen
1,323910
1,323910
that's echo %foo%
– Bob
Aug 28 '09 at 15:42
add a comment |
that's echo %foo%
– Bob
Aug 28 '09 at 15:42
that's echo %foo%
– Bob
Aug 28 '09 at 15:42
that's echo %foo%
– Bob
Aug 28 '09 at 15:42
add a comment |
set Result=0
echo start %Result%
echo Adding 4 and 2
set /a Result= 4+2
echo finish %result%
pause >nul
add a comment |
set Result=0
echo start %Result%
echo Adding 4 and 2
set /a Result= 4+2
echo finish %result%
pause >nul
add a comment |
set Result=0
echo start %Result%
echo Adding 4 and 2
set /a Result= 4+2
echo finish %result%
pause >nul
set Result=0
echo start %Result%
echo Adding 4 and 2
set /a Result= 4+2
echo finish %result%
pause >nul
answered Aug 28 '09 at 15:37
IzzyIzzy
7,85522634
7,85522634
add a comment |
add a comment |
If you have bash/perl installed (eg. cygwin), just call them to do the math:
@for /f "delims=" %%a in ('perl -e "print(%*)"' ) do @set RESULT=%%a
@echo %RESULT%
@for /f "delims=" %%a in ('bash -c "echo $((%*))"' ) do @set RESULT=%%a
@echo %RESULT%
Sample result:
c:> script.cmd 2**10/3
341.333333333333
341
add a comment |
If you have bash/perl installed (eg. cygwin), just call them to do the math:
@for /f "delims=" %%a in ('perl -e "print(%*)"' ) do @set RESULT=%%a
@echo %RESULT%
@for /f "delims=" %%a in ('bash -c "echo $((%*))"' ) do @set RESULT=%%a
@echo %RESULT%
Sample result:
c:> script.cmd 2**10/3
341.333333333333
341
add a comment |
If you have bash/perl installed (eg. cygwin), just call them to do the math:
@for /f "delims=" %%a in ('perl -e "print(%*)"' ) do @set RESULT=%%a
@echo %RESULT%
@for /f "delims=" %%a in ('bash -c "echo $((%*))"' ) do @set RESULT=%%a
@echo %RESULT%
Sample result:
c:> script.cmd 2**10/3
341.333333333333
341
If you have bash/perl installed (eg. cygwin), just call them to do the math:
@for /f "delims=" %%a in ('perl -e "print(%*)"' ) do @set RESULT=%%a
@echo %RESULT%
@for /f "delims=" %%a in ('bash -c "echo $((%*))"' ) do @set RESULT=%%a
@echo %RESULT%
Sample result:
c:> script.cmd 2**10/3
341.333333333333
341
answered Apr 17 at 21:34
moshmosh
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f60039%2fevaluating-expressions-in-windows-batch-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown