Comments in Bash

Comments in Bash

 Comments in Bash

Comments are an essential part of any programming language. It is used to describe the uses of any code or function. Similar to the other programming languages bash scripts also support comments. There are two types of comments, single-line comments, and multi-line comments.

We have described below both types of comments:

Bash – Single Line Comments

Single-line comments are started with a hash (#) symbol. As per the title, it must be finished in a single line. No newline character “\n” should be there. There is no limit to single-line comments in a shell script.

As an example, check the below sample shell script with the single-line comments.

Note: The first line (topmost line) of the script also starts with a # symbol. But that is parsed as a shebang character, not as a comment.

Bash – Multiple Line Comment

You can also use multi-line comments in bash scripts. The multi-line comments can be written in two ways.

The below example shell script will show you the first method to define the multi-line comments.

Another way of writing multi-line comments in a shell script.

The first comment starts with <<ANYSTRING and ends with the same string ANYSTRING. The second multi-line comment started with : ' and ended with a single quote ' only.

Reactions

Post a Comment

0 Comments

close