Working with Batch Scripts

Creating our own Batch Scripts

Example 1: To print “w3wiki” on the command prompt with and without using a variable.

Without using a variable 

ECHO w3wiki

With a variable

SET my_var=w3wiki
ECHO %my_var%

Arithmetic Operators in a Batch Script

List of operators :

SET /A sum=1+1     ::addition operator
ECHO %sum%     
SET /A mul=7*9     ::multiplication operator
ECHO %mul%
SET /A div=9/3     ::Division operator
ECHO %div%
SET /A assign=10   ::Assignment operator
ECHO %assign%
SET /A assign+=15  ::Increment then assignment operator
ECHO %assign%
SET /A mod= 10%3   ::Modulus/Remainder operator
ECHO %mod%

Demonstration of all arithmetic operators 


Basics of Batch Scripting

Batch Scripting consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. It is not commonly used as a programming language and so it is not commonly practiced and is not trending but its control and dominance in the Windows environment can never be neglected. Almost every task and every action can be performed and executed by a simple sequence of commands typed on the Windows Command Prompt. 

Batch Script execution

There are 2 ways to execute a batch script.

  • Type the batch script in the command prompt.
  • Write the code of script in a file and execute it through the command prompt.

Typing commands again and again on the terminal can be a very tedious task to do if we have a very lengthy code. So option 2 is generally preferred to create batch files.

Similar Reads

Creating Batch Files

Steps to create a Batch file are pretty simple:-...

Working with Batch Scripts

Creating our own Batch Scripts...

Contact Us