Batch Scripting Language Tutorial for Beginners

View more categories:

1- What is batch language?

Batch is a programming language. It is used to create script files executable on Windows operating system. Normally, normally these files have an extension of  .bat or *.cmd. When being executed, they open a " Command Prompt" window, which normally has a typical black background, white text.
The  batch files  ( *.bat, *.cmd) are called script files which can contain commands interfering operating system.
Note: a language that is equivalent to batch but used for Linux operating system is Shell, with script files ending in * .sh.

See more:
  • TODO Link!

2- Example starting with Batch

Batch uses  @rem to start a Comment line, which is used to annotate the purpose of command lines in the program and they are ignored when the program excutes.
To start Batch language, we create a file with the  hello.bat name, and write statements showing on the screen the line of "Three", "Two", "One", "Hello World!".
@rem My First Batch file!

@echo off

echo Three

echo Two

echo One

echo Hello World!

Double click on hello.bat file to execute it.
You can also execute Batch file from CMD. Open the CMD and CD programs to go to the folder containing the file to be executed.
Execute the  hello.bat file from  CMD:
echo Show a line on screen
pause Suspend the program and wait for a user to press Enter button to continue.

@echo on/off

The  @echo off command is used to stop the command prompt display mode. This mode is on by default. Let's see the difference between @echo off and  @echo on by the following illustration:

View more categories: