How to add block comment in shell script

The shell script is a set of instructions which are written using a programming language called bash. It is used for running commands, managing files and directories on your computer. Shell scripts often contain many lines of code and sometimes it becomes difficult to find the exact line that needs to be edited or added. In such cases, block comments can help you out by putting a comment in front of each section of code you want to edit so that you can easily find those lines later on without having to scroll through all other lines first.

How do I insert a comment in a bash script?

  • The hash symbol: #
  • The pound symbol: $
  • The double-dash symbol: —
  • The semicolon: ;
  • The single-dash symbol: –

How do I comment in bash shell?

You can use # at the beginning of a line to create a comment. This will tell the shell to ignore everything that follows on that line.

You can also use it at the end of a line, which will comment out everything from there until the end of the file.

Finally, if you want to have some sort of commentary near your code but not in its entirety, use # at the beginning of each relevant section and then ; at the end (or vice versa).

How do you comment in a batch script?

The REM command is used to add comments to batch scripts.

A simple example would be:

REM This is a comment line

The comment line can be any length, but it must start with an equal sign (=), followed by one or more characters, and then end with a carriage return (CR).

How do you comment multiple lines?

As mentioned, the syntax for a shell comment is as follows:

# comment 1

You can also use C-style comments in your shell scripts. To do so, simply enclose the text you want to remain untouched by the script with two forward slashes (//):

// This line will be ignored by the script and all of these will be ignored as well.

There are many options for commenting out multiple lines of code, including using shell scripts themselves. You can use #!/bin/sh at the top of your file and put all your code in there. Then put another #!/bin/sh at the bottom of your file and then you don’t have to worry about compiling anything because it already runs from that first line!


In this article, we will be discussing the various ways in which you can add comments in your shell script. We will also discuss how to format these comments and some of the best practices for adding them into your scripts. If you wants to read blogs on ” Block comments in Java” ¬†click here.