How to insert comments in shell scripts

In shell scripting, # is used for inserting comments.

Watch Free Movies

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.

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.

Scroll to Top