Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline bash comment etiquette (#+)

Tags:

bash

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?

like image 996
simont Avatar asked Dec 19 '12 08:12

simont


People also ask

How do you comment multiple lines in bash?

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.

How do you comment out a line in bash?

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.

How do you comment out a line in a shell script?

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.

Is shell script support multi line comment in bash 1 point Yes No may be I don't know?

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.


1 Answers

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.

like image 104
Brian Campbell Avatar answered Oct 17 '22 20:10

Brian Campbell