Home » Bash Comments

Bash Comments

In this topic, we will understand how to insert comments in a Bash Script file.

Comments are the necessary part of any programming language. They are used to define the usage of any code or function. Comments are the strings which help in the readability of a program. They are not executed when we execute the commands in Bash Script file.

Bash script provides support for two types of comments, just like the other programming language.

  • Single Line Comment
  • Multiple/ Multi-Line Comment

Bash Single Line Comment

To write single line comment in bash, we have to use hash (#) symbol at the starting of the comment. Following is an example of Bash Script which contains single-line comments in between commands:

Bash Script

Bash Console View

The above script will look like the following image in the Bash console:

Bash Comments

Output

If we enter a name as tutoraspire, then the output will look like this:

Bash Comments

Here, it can be clearly seen that comments are ignored while the execution of the commands is in process.

Bash Multi Line Comment

There are two ways to insert multi-line comments in bash scripts:

  • We can write multi-line comments in bash scripting by enclosing the comments between <<COMMENT and COMMENT.
  • We can also write multi-line comments by enclosing the comments between (: ‘) and single quote (‘).

Read the following examples which will help you to understand both the ways of multi-line comments:

Method 1:

Bash Script

Bash Console View

Bash Comments

Output

Bash Comments

Method 2:

Bash Script

Bash Console View

Bash Comments

Output

Bash Comments

Conclusion

In this topic, we discussed how to insert a single line and multi-line comments in Bash Script file.


Next TopicBash Quotes

You may also like