What is REM?
Rem is a short form of the remark. In the system, a file remark is placed to skip line loading. By placing "REM" in front of a line, a remark is created. Using REM remarks the whole line and prevents loading the line. When REM is used along with batch files, and if the echo is off, then line is not shown.
Example
@echo off
REM this line won't be seen when the echo is off
Echo Hello Tutorialandexample!
In the example given above, the first line written after REM won't be seen as it is skipped. Then only "Hello Tutorialandexample!" is seen on the screen.
Another way to remark any line in the batch file is by placing the two colons(::) at the line start. Then these two colons won’t show the line whether the echo is off within the batch file.
:: the line is not seen forever
Echo Hello Tutorialandexample!
REM is a way of inserting remarks into a batch file. In the Windows Command Processor, i.e., Command Prompt REM is present.
REM is used as a command in java as we use "//" to write a command. Rem is an inline command which means that the line is executed as a comment till the end only. It won't be used to write multi-line comments. When the user wants to write multi-line comments using REM, then the user should use multiple Rem commands.
Comments make the code more readable by giving necessary insights to the user. Consider the following code to understand the usage of the Rem command in different scenarios.
- @echo off
this command is used in the batch file to prevent all commands from echoing to the screen.
- echo %~f0
Here REM displays the full path of the file.
- echo %~t0
REM displays the timestamp of file creation.
REM used to create an inline comment
As discussed, Rem is an inline comment; let’s see an example
REM this code is used to display hello
echo hello!
REM used to create multi-line comments:
We should use multiple Rem commands for creating multi-line comments, as in the code snippet.
REM this code tells the time
REM displays time until milliseconds
REM the time is given basis on the current time zone
echo | time
In the above example first three lines are comments that describe the functionality of the last code line.
One more important point in the REM discussion is that a single quotation mark ( ' ) can also be used as an alternative to REM.
Example
REM this is a comment
' This line is also a comment
Hiding the REM lines from showing in a batch file
REM command is used to remark the lines. By remarking the lines, the main use is that line is skipped from execution. But one main problem is that if the @echo off is not placed in the batch file, then still the lines will be echoed to the screen without the skip.
To prevent the lines from echo to the screen, there are three ways as follows:
- To the batch file adding @echo off
Adding @echo off in the batch files first hides all the commands along with REM lines. - Interchange REM with @REM
When the user wishes to show the commands even if the batch file is running, but if the user hides the REM lines, then use @REM instead of REM. - Using "::" in place of REM
Usage of "::" instead of REM as the remark command halts the remarked line echo.
In the above blog, we have been discussing the batch files, so we will understand what these batch files are to get full clarity of the topic.
What is a Batch file?
A batch file can be either of the following explanations.
- A batch file, sometimes also referred to as a batch job, is a processing of a group of commands in sequence without the requirement of user intervention (i.e., without having the user input). Batch files are used for loading programs and running multiple processes simultaneously, and they are also used to perform repetitive or common tasks.
- A batch command executes several commands, and a batch command is a Recovery Console Command.