While you are writing any code or scripts, it is very common practice to comment out code, so in this article, I have mentioned how we can comment single or multiple lines block comments in Bash (Linux scripts).

multiple-lines-comment-bash

Block Comment using << ''

In Bash Script, you can write block comment starting <<'#SomeText' and end with #SomeText , here is an example

# Hello World Program in Bash Shell

<<'###BLOCK-COMMENT'
Some lines here
Yes this block comment
Will not execute
###BLOCK-COMMENT
echo "Hello World!"

When we execute the above script, the output would be as below

Hello World!

As you can see we have used '###Block-Comment' text to denote start and end of comment, you can use any other text also, but start/end text must match.

This method is known quoted HEREDOC marker.

Multi-Line Comments Using : ` :

We can also try this second method :` to start comment and end it with :

: '
echo "This will not execute"
echo "We commented it out"
'

echo "Bye"

Output:

Bye

Single Line Comments in Bash

To Write Single-line comments in Bash script, we simply use "#" before writing any comment for the line, for example:

# this is a single line comment in bash
echo Learn Bash Comments

This will print the output

Learn Bash Comments

That's it, hope it helps in understanding how to do multi-line or block comments in Bash or single-line comments.

You may also like to read:

HTML Comment Multiple lines (Block comments)

C# Comments with example (Single or Multi-line)

What is Eclipse Comment shortcut?

How to comment multiple lines in Visual Studio (VS) Code