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;








5















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!










share|improve this question




























    5















    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!










    share|improve this question
























      5












      5








      5


      1






      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!










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 28 '09 at 15:27









      raoulssonraoulsson

      1,86862729




      1,86862729




















          3 Answers
          3






          active

          oldest

          votes


















          7














          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


















          3














          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






























            0














            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





            share|improve this answer























              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
              );



              );













              draft saved

              draft discarded


















              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









              7














              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















              7














              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













              7












              7








              7







              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















              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














              share|improve this answer



              share|improve this answer








              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

















              • 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













              3














              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



























                3














                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

























                  3












                  3








                  3







                  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













                  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












                  share|improve this answer



                  share|improve this answer










                  answered Aug 28 '09 at 15:37









                  IzzyIzzy

                  7,85522634




                  7,85522634





















                      0














                      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





                      share|improve this answer



























                        0














                        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





                        share|improve this answer

























                          0












                          0








                          0







                          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





                          share|improve this answer













                          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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 17 at 21:34









                          moshmosh

                          112




                          112



























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

                              What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

                              Why did Thanos need his ship to help him in the battle scene?Which actor plays Thanos in the Avengers mid-credits scene?Are there economic implications portrayed in comics where the buildings and cities are ruined almost daily?Old X-Men comic where team travels to alien world with a ring-like sun that needs recharging?Why does Ego need help sleeping?Is there an objective answer to who “the strongest Avenger” is?How did Banner get unstuck?Why did Thanos get hit?How did Thanos (or anyone) know the Infinity Stones would give him this power?Did Thanos leave Eitri alive for his after-sales service?In Avengers 1, why does Thanos need Loki?