Skip to content
Related Articles

Related Articles

Improve Article

Comments in Shell Script

  • Last Updated : 10 May, 2021

Comments are the useful information that the developers provide to make the reader understand the source code. It explains the logic or a part of it used in the code. Comments are usually helpful to someone maintaining or enhancing your code when you are no longer around to answer questions about it. These are often cited as a useful programming convention that does not take part in the output of the program but improves the readability of the whole program.

There are two types of comments:

  1. Single-line comment
  2. Multi-line comment

Single-line comments: 

A single-line comment starts with hashtag symbol with no white spaces (#) and lasts till the end of the line. If the comment exceeds one line then put a hashtag on the next line and continue the comment.

The shell script is commented out prefixing # character for single-line comment.

Syntax
#This is a comment

Example:



#Single line comment
echo "hello world"

Output:

Comments in | shell script

Multi-line comments:

Multi-line comment is a piece of text enclosed in a delimiter (”) on each end of the comment. Again there should be no white space between delimiter (‘ ‘). They are useful when the comment text does not fit into one line; therefore need to span across lines. Multi-line comments or paragraphs serve as documentation for others reading your code. See the following code snippet demonstrating multi-line comment:

Syntax:
: '
This is a
Multi-line comments'

Example:

echo "multiline comments"
: '
Print some word'

Output:

Comments in | shell script

My Personal Notes arrow_drop_up
Recommended Articles
Page :