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 #.

If you are really interested in bash scripting, read the next shell scripting article.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , ,
Posted in The Linux and Unix Articles!
One comment on “How to insert comments in shell scripts
  1. chrystus says:

    Good news! Thx!

Leave a Reply

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

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!