Comments in Shell Script
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:
- Single-line comment
- Multi-line comment
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
#Single line comment echo "hello world"
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'
echo "multiline comments" : ' Print some word'