Batch Script automates repetitive command sequences. Scripting alleviates this necessity by automating these command sequences to make one’s life at the shell easier and more productive. In most organizations, Batch Script is incorporated in some way or the other to automate stuff.
What are the features of Batch Script?
Can read inputs from users so that it can be processed further.
Has control structures such as for, if, while, switch for better automating and scripting.
Supports advanced features such as Functions and Arrays.
Supports regular expressions.
Can include other programming codes such as Perl.
What are the common uses of Batch Script?
Setting up servers for different purposes.
Automating housekeeping activities such as deleting unwanted files or log files.
Automating the deployment of applications from one environment to another.
Installing programs on various machines at once.
How are Batch Scripts stored?
They are stored in simple text files containing lines with commands that get executed in sequence, one after the other. These files have the special extension BAT or CMD. Files of this type are recognized and executed through an interface (sometimes called a shell) provided by a system file called the command interpreter. On Windows systems, this interpreter is known as cmd.exe.
How to run Batch Scripts
Batch file run on simple click. Alternatively, it can be run in a command prompt or the Start-Run line. In such case, the full path name must be used unless the file's path is in the path environment.
Here is a simple example of a Batch Script when run deletes all files in the current directory.