ECHO command is great for communicating with the user. Messages can be delivered to the end-user. This is great for giving the user a list of choices and wanting feedback before a particular action is performed. Try experimenting with different formats for delivering messages to the user. For example, centering the text using spaces. Or adding hyphens and exclamation marks for borders:
echo ! Your hello message... !
You can create a line break, a blank line, by typing
ECHO. but notice the period. The ECHO and period combination is what creates the line break. Example:
:: Prints 'Hello World' to the screen...
:: with a line break in between the words.
Lines 2, 3 and 4 in this batch file example are comments or remark statements. When writing batch scripts you will want to place two comments at the top of the file. Coding standard style should be in place, which improves the quality of software which results in fewer bugs which is easier to maintain and use. The first line should contain the name of the file and the second remark statement should include a brief statement about the following program. This helps yourself when you start writing many batch files and it also helps someone read your script that might not be as familiar with it as you. This could perhaps be the case of having a friend debug your file.
The first remark statement has the
REM signifying a remark. These are used in every programming language to add comments to your code. Since your beginning batch programs will be smaller programs, we won't need very many remark statements though it is a good idea to get in the habit of documenting your scripts well. Remark statements are ignored by DOS. Notice the
:: (two colons) in the next remark statement. This is another way of commenting your batch scripts. The double colon approach is a better way of commenting your code because the command prompt will entirely ignore this line making your program run faster.
Yes, REM is ignored however the command prompt takes a more detailed approach at reading the comment and it takes a longer amount of time to execute. The double colon makes for a quicker program. This gives you advantages when you start building more complicated programs and you start adding more of them. For the preceding reasons we will not use the
REM command rather we will use the double colons when commenting our code.
Another characteristic of batch scripting is that line breaks (spaces between lines) in your Notepad file are ignored. Here they are used merely for readability. Notice the two above / previous examples each have a different line break scheme. The first implements a double space layout for better readability. The second is more compact.
ECHO is similar to the
ECHO is used for displaying a string of text to the screen.
Finally, we have the
PAUSE command. Your program will run just fine without this. However, you will not be able to see your output; the text
Hello World in this example. If you include the
PAUSE command you will see the text string
Press any key to continue... If you do not include this command the command prompt will appear, then flash away quickly. Run the program without this and note the difference.
Note that batch commands are usually not case sensitive. All caps are shown in this article to help you identify the batch code. When an instance arises where case-sensitivity will matter it will be explained.
Please do not hesitate to contact our support department with any possible further questions or to solve practical issues connected with Command line email and batch files.