1. Home
  2. Bash
  3. Bash Tutorial
  4. Bash – Comments

Bash – Comments

Comments in Bash

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

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 commends 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 started with <<ANYSTRING and ends with same string ANYSTRING. The second multi line comments started with : ' and ended with single quote ' only.