Situatie
In batch scripting, the echo command can be used to display a message, variable value, or system information on the console. The command can be followed by a message or text string enclosed in double quotes. For example, echo “Hello, World!” will display the message “Hello, World!” on the console.
Why use Batch Script – Echo Command?
Here are a few reasons why the echo command is commonly used:
- Displaying messages: The echo command can be used to display messages or information on the console or in a text file. This is useful for providing feedback to the user, displaying error messages, or providing instructions.
- Displaying variables: Batch scripts often use variables to store information or data. The echo command can be used to display the value of a variable on the console or in a text file, making it easier to debug and troubleshoot scripts.
- Debugging: The echo command can be used to debug scripts by displaying the values of variables, commands, or system information. This can help identify errors and improve the efficiency of scripts.
- File output: The echo command can be used to redirect output to a file, making it easier to save and share information. This can be particularly useful when generating reports or logs.
- Script automation: Batch scripts can automate repetitive tasks, making them more efficient and less prone to human error. The echo command can be used to provide feedback and ensure that scripts are running as expected.
Solutie
Pasi de urmat
Open your preferred directory using the file explorer and click on View. Then go to the Show/hide section and make sure that the “File name extensions” are ticked.
Now create a text file and give it a name (e.g. 123.bat) and edit it with notepad and write the following commands and save it.
echo on echo "Great day ahead" ver Now save the file and execute this in the CLI app (basically in CMD). The output will be like the following.
It was a very basic example of batch scripting. Hereby using echo on we ensure that command echoing is on i.e. all the commands will be displayed including this command itself. The next command prints a string “Great day ahead” on the screen and the ver command displays the version of the currently running OS. Note that the commands are not case sensitive (e.g. echo and ECHO will give the same output).
When echo is used without any parameter it will show the current command echoing setting (on/off).
Syntax:
echo
Printing a message on the screen using ECHO:
We can print any text message on the screen using echo. The message is not needed to be enclosed within single quotes or double quotes ( ‘ or “), moreover any type of quote will also be printed on the screen.
Syntax:
echo <any text message to print on the screen>
Leave A Comment?