Rem (abbreviation of remark) is a command (internal) found inside the Windows Command Processor Command Prompt, that allows for inclusion of comments inside batch programs. Comments are supported by most Programming languages usually via special syntax that is associated to them. Ex. Python using pound sign/hashtag ( # ) to denote a inline comment. Rem command is for inline comments, therefore the comment would only be valid till the end of the current line (or first occurrence of CRLF) Though multiline comments can be created using multiple Rem command on separate lines. In this article we will take a look at the Rem command, and would get to know about various uses for it.
Description of the Command :
Records comments (remarks) in a batch file or CONFIG.SYS.
REM [comment]
*The above output can be obtained by executing rem /? command in the commandline
Using the Command : Comments are generally used to add more intel to the code. It helps in providing an insight to what the creator of the code, was thinking while writing it. It is also useful for providing some pointers or addendum related to the code. Comments overall help in reducing the complexity of the code, by being a sort of human-readable form of code. They also help to guide readers, who are unaware of the language.
For Example, let's take a look at the following code snippet:
@echo off
echo %~f0
echo %~t0
To someone who has never seen the aforementioned syntax, the code may be quite cryptic at first. But if comments are added to the code:
REM Used to disable echo of command entry and current working directory
@echo off
REM Displaying the full path (absolute Path) of this file
echo %~f0
REM Displaying the timestamp of creation of this file
echo %~t0
The code becomes clear on its functionality, and one can easily guide through its workings.
Creating Inline Comments :
Inline comments can be created by using the REM command at the beginning of the line and then typing in the comment.
For example,
REM This code will display hello world
echo hello world!
Inline comments could also be added to the end of the line (preceded by some code) by using the & REM construct.
For example,
echo Hello World! & REM This code will display hello world
Creating Multiline Comments :
Multiline comments can be created by using multiple rem commands, that span several lines.
For example,
REM This code will tell the current time
REM The resolution of the time will be until milliseconds
REM The time will be based on the current timezone
echo | time
Note -
Comment creation exists through various other means as well. Ex. There exists other types of ~comments which allows for comments in between a statement. But they are not the documented way of commenting code, and exists due to workaround of other commands/syntaxs. Also, those are outside the scope of this article.
Similar Reads
cmd | Dir command The dir command is one of the most useful commands while navigating the command line, and is present in its different forms in several operating systems. In this article, we will look at the Dir command and learn several use cases for it.What is the dir Commanddir command in Windows OS is a built-in
9 min read
Cd cmd command Cd is the abbreviation or synonym for chdir. It is a command found inside the Windows Command Processor (cmd) that allows for change of the current working directory of a shell instance. The CWD (Current Working Directory) is a path (of a directory) inside the file system, where the shell is current
3 min read
cmd | cls command Cls is a internal command found inside windows command interpreter cmd, that is used for clearing the console window. It does so by removing the entry of all previously entered commands, and their corresponding outputs. The command was first introduced in the MSDOS Version 2. Initially it was for co
2 min read
Introduction to Linux Shell and Shell Scripting If we are using any major operating system, we are indirectly interacting with the shell. While running Ubuntu, Linux Mint, or any other Linux distribution, we are interacting with the shell by using the terminal. In this article we will discuss Linux shells and shell scripting so before understandi
8 min read
How to Use Command Prompt - Windows Command Prompt Guide Learn how to manually run the Command Prompt in different versions of Windows - The Windows Command Prompt (CMD) is a powerful tool that allows users to execute commands, automate tasks, and troubleshoot system issues efficiently. Whether youâre a beginner looking to learn basic CMD commands or an a
5 min read