Skip to content
Related Articles

Related Articles

Improve Article

cmd | Rem command

  • Last Updated : 16 Oct, 2020
Geek Week

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 the 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/syntaxes. Also, those are outside the scope of this article.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :