How to insert comments in shell scripts

How to insert comments in shell scripts

In this tutorial I will show you, how to insert comments in shell scripts.

In shell scripting, # is used for inserting comments.

Every line beginning with # (except the shebang #!) will not be executed!

# this is a commented line!

Comments can also occur following the end of a command.

echo "hello" # this display "hello" in your terminal

Note: When you edit configuration files, comment the lines you need to delete. This way, it will be much easier to go back to the previous setting, when you need to.

A commented line starts with # and terminates at the ending of the line. There is no method (character) for terminating a comment. So, A command may not follow a comment on the same line.

Of cource, the # will be ignored if is it quoted or escaped.

Example:
quoted #:
$ echo "The # does not begin art a comment here."
output: The # does not begin a comment here.

escapted #:
$ echo The /# does not begin a comment here.
output: The /# does not begin a comment here.

The standard quoting and escape characters (” ‘ \) escape the #.

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!
 
Enjoyed this video?
How to insert comments in shell scripts
"No Thanks. Please Close This Box!"