In the last lesson, we introduced the idea of batch files. But to really learn about them, you should practice creating some batch files. Please note that you can generally get similar results using the command prompt window in your version of Windows, but I am using DOS 6.22 commands here, and I test and run all of my batch files on a computer running DOS 6.22. It is possible that some small difference in versions may affect your results, and I have not tested these on every platform in existence.
I suggest that you create a temporary directory on your machine just for playing around with these batch files. It is a bad habit to save these things in the root directory. First, you may not remember which files are your
test files and which are vital system files, and later delete something important by mistake. Second, the root directory, like all directories, can only hold a limited number of files, so you don’t want to use up slots with this stuff. Third, if you need to find one of them, it is a lot easier if they are all in their own area. I call mine c:\dostemp\, which I will assume for this lesson
The echo command controls what gets shown on the screen when you run a batch file. You can use the echo command to stop the display, or to make something display, as you wish. For instance, here is a simple one line batch
echo Hello people, how is life in the carbon world?
If you create this file and run it, you will see the sentence displayed on the screen. Try creating this file as test1.bat in your temporary directory.
This can be useful when you want to display some piece of text. For instance, in many DOS installation programs, you would see something on
the screen that told you to wait while the installation program was doing something. Or, in a networked environment you could display a login message.
Another use of the ECHO command has to do with the way that batch files normally execute. A batch file just executes DOS files in order, much the same as if you were at the keyboard typing in each command. Well, if you
were at the keyboard, you would see each of the commands you typed. Try creating the following file, which is called test2.bat:
copy test1.bat test1a.bat
When you execute this file, you should see, first, your command itself, running in your current working directory, followed by the computer
reply that a file was copied.
C:\DOSTEMP\>copy test1.bat test1a.bat
1 file(s) copied
Now, seeing this displayed on the screen may not bother you, but there are times when you don’t want to see it, or you don’t want others to see what is in the file (such as in a login script). You can use the ECHO command to stop that. So edit your test2.bat file to add the following line, which should be the very first line in your file:
Now, run test2.bat again, you will see that the command is no longer displayed on the screen. However, the first line, ECHO OFF, is displayed.
You can stop this by using the @ symbol at the beginning of the first line:
The @ symbol can be used at the beginning of any line to stop the display of that line in the batch file. This may sound similar to the REM command, but there is a big difference. The REM command stops the line from being executed, but the @ symbol still executes the line, it just stops the display.
In most batch files, it makes more sense to turn off the display of all commands, so you usually see the @ symbol used only in the very first
line to turn off the display of the ECHO command.
What if you wanted to display a blank line? You might think that the ECHO command all by itself, with nothing after it, would do the trick, but you would be wrong in that case. The ECHO command by itself asks the computer to respond whether ECHO is on or off, so you will get “ECHO is off” displayed on the screen. The way to get a blank line is to use a + sign immediately after the ECHO: ECHO+
Stupid DOS Tricks
While the ECHO command is intended primarily for use within batch files, it can be used within DOS. A practical joke you could pull on someone in the DOS days was to get to their computer while they were at the old water cooler, and type the command “echo off” at the DOS prompt. It would
have the effect of turning off the display of the DOS prompt. Since only the
very geekiest of geeks had ever seen anything like this, it drove most people