DOS Batch in Plain English
Home News & Articles Tutorials Downloads About this site

The beginning

First, let's open a DOS box.  Goto Start>Programs>MS-DOS Prompt.  If that is missing, Goto Start>Run & run 'COMMAND' (without the quotes).  This is DOS.  This is your new home.  Get comfy.

If you're not familiar with DOS, check out my DOS in Plain English Tutorial.

The program of choice is NOTEPAD, a basic text editor, but you're welcome to use the older, more DOS-ey  program called "EDIT".  To run EDIT, type 'edit' at the DOS Prompt.  Now you have a blue screen.  EDIT is a great program if Windows ever gets hosed down to the 'unusable' level.  Play around with EDIT if you want, but we will continue on with NOTEPAD and sell out horribly.

Leave the DOS box open and Goto Start>Run & type 'NOTEPAD'.  Now arrange NOTEPAD and the DOS box so that you can see them at the same time.  In notepad type the following:

@ECHO OFF

REM A simple batch file

ECHO Hello World!

Goto File>Save As.  Change the folder to C:\Windows\Desktop (assuming that windows is on C:) and name the file 'Hello.bat'.  Click on save.  You'll notice a file popup on your wallpaper if you did it right.  In your DOS box, change to C:\Windows\Desktop and type 'Hello'.

Breakdown:  @echo off turns off echo.  Why the @?  In notepad, take out the @, save Hello.bat and run 'Hello' back in the DOS box.  If you notice, @ makes that line not echo either.  It just makes it look nice, that's all.  Leaving echo on is good for troubleshooting your own batch file (debugging). 

REM is short for remove.  Putting REM in front of any line tells Command.com to ignore that line.  At the DOS prompt, type 'REM cls'  Nothing happens.  Take out REM.  Now it works.  REM is good for commenting.  Commenting is good for not confusing yourself next month when you come back to finish something.  Good programming practice.

Echo says whatever you tell it to.  Very useful for user-prompts and questions.  You can do very good things with echo.  For example, change our Hello.bat file to say:

@ECHO OFF

REM A prettier, simple batch file

ECHO ==========

ECHO.

ECHO Hello World!

ECHO.

ECHO ==========

Remember to save the file before you run it.  Notepad just keeps it in memory.  Command.com just reads it from the disk.  Bring the two together in a Batchy Wedlock with a little File>Save.

To illustrate @echo off, take it out of our prettier batch file with a quick REM.  See how batchy it can get all of a sudden?

previous

next

Page 2

Page 1 - Introduction

Page 2 - The beginning

Page 3 - Variables, Loops and What-ifs

Page 4 - Pipes, Redirection and Switches

Page 5 - Where to go with batch

hide

DOS - Disk operating system.  Usually meaning Microsoft's release of MS-DOS.