The Advanced Bash-Scripting Guide makes extensive use of multiline comments in examples, of the form:
echo ls -l | sh
# Passes the output of "echo ls -l" to the shell,
#+ with the same result as a simple "ls -l".
(found in the explanation for the pipe |
symbol). Other multiline comments look like this:
#!/bin/bash
# rpm-check.sh
# Queries an rpm file for description, listing,
#+ and whether it can be installed.
# Saves output to a file.
#
# This script illustrates using a code block.
(example 3.2 in the linked page).
What is the ratonale for the use of #+
? Some multiline comments it seems to indicate that the comment continues on in the next line, but others it doesn't.
Is there a 'bash-scripting comment etiquette` that I should (attempt to) follow in my own scripts?
Method 1: Using <<comment: In Shell or Bash shell, we can comment on multiple lines using << and name of comment. we start a comment block with << and name anything to the block and wherever we want to stop the comment, we will simply type the name of the comment.
When writing bash scripts, any text after a hash sign ( # ) indicates the start of a comment, and any text after # in the same line does not execute. When using a text editor or IDE, comments are colored differently from the rest of the code.
A single-line comment starts with hashtag symbol with no white spaces (#) and lasts till the end of the line. If the comment exceeds one line then put a hashtag on the next line and continue the comment. The shell script is commented out prefixing # character for single-line comment.
Multiline Comments in Bash Unlike most of the programming languages, Bash doesn't support multiline comments. The simplest way to write multiline comments in Bash is to add single comments one after another: # This is the first line. # This is the second line.
It appears that the author of the Advanced Bash Scripting Guide uses that on lines which continue a sentence from the previous line.
This is not a standard stylistic choice; this appears to be a stylistic quirk of the author of the Advanced Bash Scripting Guide.
I will note that while there is some good technical information in the Advanced Bash Scripting Guide, the coding style is fairly non-standard. I wouldn't use it as an example of what good Bash coding practices are. A somewhat better resource is the Bash FAQ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With