Adding Comment To a Script

In shell scripting, a comment is a readable explanation in a script that is ignored by the interpreter, you can either add a comment about what the script does or you can write a comment about what a specific function/section does in the script.

Either way, a comment makes code easier for humans to understand the code when viewed later on.

Let’s see an example:

# Description   : A description of what the script does
# Version       : 1.0
# Author        : Mr. Devsrealmer
# Date          : 30/07/2020

A comment begins with a hash (#) at the beginning of a word, once the shell sees that, it ignores it. However, the first line has #!/bin/bash: This is always the first line of every bash script, and also known as shebang or hashbang.

This looks like a comment, the difference is that it appends an exclamation mark to the comment.

What this line does is to instruct the shell which interpreter to use to run the commands inside the script. If you are running a python script, you would use #!/usr/bin/python, Since we’re writing a bash script, we used #!/bin/bash. you get the idea.


Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *