Practical: Your First Batch Script
A batch file is simply a text file containing a list of commands that are executed in sequence. They end with the .bat or .cmd extension.
The Mission
You will create a simple script called hello.bat that:
- Clears the screen.
- Prints a welcome message.
- Pauses so the window doesn't close immediately.
Step 1: Create the Script
We will use copy con to write the script directly.
Command Prompt
C:\Users\User>copy con hello.bat
Step 2: Run the Script
Execute it by typing its name.
Command Prompt
C:\Users\User>hello.bat
Key Commands Explained
@echo off: Prevents the commands themselves from being displayed, showing only their output.cls: Clears the terminal screen.pause: Stops execution and waits for user input. Without this, the script might run and close the window instantly.
Step 3: A More Useful Script (System Info)
Let's make a script that shows IP information.
Command Prompt
C:\Users\User>copy con network.bat
Knowledge Check
1 / 3What file extension is used for batch scripts?