Comments

As any good software engineer could tell you, placing relevant comments in your code increases the quality of the code. A comment is nothing more than a bit of text explaining what you're doing, prefixed by a special character that ensures the language you're coding in does not interpret the text. For Bash, this character is the number sign # (currently more famous for its use in #HashTags). When you're reading other sources, it may also be referred to as the pound sign or the hash. Other examples of comment characters are // (Java, C++), -- (SQL), and <!-- comment here --> (HTML, XML). The # character is also used as a comment for Python and Perl.

A comment can either be used at the beginning of a line, which ensures the entire line does not get interpreted, or further in a line. In that case, everything up until # will be processed. Let's look at an example of both of these in a revised Hello World script:

#!/bin/bash

# Print the text to the Terminal.
echo "Hello World!"

Alternatively, we can use the following syntax:

#!/bin/bash

echo "Hello World!" # Print the text to the Terminal.

In general, we prefer putting comments on their own line directly above the command. However, once we introduce loops, redirection, and other advanced constructs, an inline comment can ensure better readability than an entire line. The most important thing to remember, though, is: any relevant comment is always better than no comment, whether full line or inline. By convention, we always prefer to keep comments either really short (one to three words) or use a full sentence with proper punctuation. In cases where a full sentence would be overkill, use a few keywords; otherwise, opt for the full sentence. We guarantee it will make your scripts look much more professional.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.28.133