facebook youtube pinterest twitter reddit whatsapp instagram

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.


Related Post(s)

  • (Bash Script) Automate Multiple Classicpress & Wordpress Installation + [Caching and SSL]

    If you are tired of using control panels (I am because they are mostly not secure, and most comes loaded with bundles of useless stacks), and want to do everything on the server level, I wrote a menu

  • Understanding The Four (4) Ways Command-Line Runs Shell Script

    Sometimes we need to think like the command line shell in order to understand how things are done in the background, this would make debugging a breeze. In this guide, you would learn all the variou

  • Script to Replace/substitute Multi Occurrences of A String in Files

    There are a couple of ways you can replace a string in a file, and an example is using the mv command, but what if you want to replace multiple strings at once, then you might consider creating a loo

  • Bash Script For Optimizing ClassicPress & WordPress Images in Bulk

    Out of frustration of the way different plugin optimizes images (which is super limited, and not effective; it has never been for me)in the WordPress world, I decided to create a script that does it

  • read prompts in bash script

    We've previously taken a quick look at the builtin read command, where we use the built-in read to populate the $REPLY variable, which holds the value of read when a variable is not supplied to read

  • Using read in a Bash Script

    We previously looked at using echo with options in a shell, in this guide we would combine it with read command to prompt for user input. Create and open up a new text file: nano $HOME/bin/hw3.sh Ad