Skip to contentSkip to conversation

Document bash style we prefer for if and functions

PATCH In review Heiko Voigt 2 participants 4 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Document bash style we prefer for if and functions

During discussion of other patches these preferences have been revealed. Lets add them to the guidelines.

---
 Documentation/CodingGuidelines | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/CodingGuidelines +6 -0
index 4557711..0a07990 100644
@@ -76,11 +76,16 @@ For shell scripts specifically (not exhaustive):
 
  - We do not use Process Substitution <(list) or >(list).
 
+ - We prefer "then" on the next line for if statements.
+
  - We prefer "test" over "[ ... ]".
 
  - We do not write the noiseword "function" in front of shell
    functions.
 
+ - We prefer a space between the function name and the parentheses.
+   E.g.: my_function ()
+
  - As to use of grep, stick to a subset of BRE (namely, no \{m,n\},
    [::], [==], nor [..]) for portability.
 
@@ -97,6 +102,7 @@ For shell scripts specifically (not exhaustive):
    interface translatable. See "Marking strings for translation" in
    po/README.
 
+
 For C programs:
 
  - We use tabs to indent, and interpret tabs as taking up to
Signature · 1 line
1.7.12.rc2.11.g5d52328
#1 lore raw
Quoted 13 lines · Heiko Voigt

During discussion of other patches these preferences have been revealed. Lets add them to the guidelines.

---
 Documentation/CodingGuidelines | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/CodingGuidelines +0 -0
index 4557711..0a07990 100644

Documentation/CodingGuidelines For shell scripts specifically (not exhaustive): · line 80

Quoted 5 lines
Documentation/CodingGuidelines +2 -0
@@ -76,11 +76,16 @@ For shell scripts specifically (not exhaustive):
 
  - We do not use Process Substitution <(list) or >(list).
 
+ - We prefer "then" on the next line for if statements.
+

This is not limited to "if". An easy rule of thumb is to write the control structure _without_ using semicolon.

That is:

	if test ...
        then
            ...
	else
	    ...
	fi

	while test ...
        do
        	...
	done

not

	if test ...; then
            ...
	else ...;
        fi

        while test ...; do
	    ...
	done

Documentation/CodingGuidelines For shell scripts specifically (not exhaustive): · line 88

Quoted 8 lines
Documentation/CodingGuidelines +3 -0
  - We prefer "test" over "[ ... ]".
 
  - We do not write the noiseword "function" in front of shell
    functions.
 
+ - We prefer a space between the function name and the parentheses.
+   E.g.: my_function ()
+

Also opening "{" on the same line, i.e.

	myfunc () {

Documentation/CodingGuidelines For shell scripts specifically (not exhaustive): · line 106

Quoted 11 lines
Documentation/CodingGuidelines +1 -0
  - As to use of grep, stick to a subset of BRE (namely, no \{m,n\},
    [::], [==], nor [..]) for portability.
 
@@ -97,6 +102,7 @@ For shell scripts specifically (not exhaustive):
    interface translatable. See "Marking strings for translation" in
    po/README.
 
+
 For C programs:

Probably not needed, as there is no such double space between C and Documentation sections.

Quoted 2 lines
Documentation/CodingGuidelines +0 -0
  - We use tabs to indent, and interpret tabs as taking up to
#2 lore raw

PATCH v2 1/1 add some bash style we prefer

During discussion of other patches these preferences have been revealed. Lets add them to the guidelines.

---
Here an updated version of the patch.

Quoted 10 lines · Junio C Hamano

Review For shell scripts specifically (not exhaustive): · line 106

Quoted 6 lines · Heiko Voigt
(quoted diff) +1 -0
@@ -97,6 +102,7 @@ For shell scripts specifically (not exhaustive):
    interface translatable. See "Marking strings for translation" in
    po/README.
 
+
 For C programs:

Probably not needed, as there is no such double space between C and Documentation sections.

Sorry about that whitespace noise.

Cheers Heiko

 Documentation/CodingGuidelines | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/CodingGuidelines +8 -0
index 4557711..e70d110 100644
@@ -76,11 +76,19 @@ For shell scripts specifically (not exhaustive):
 
  - We do not use Process Substitution <(list) or >(list).
 
+ - We prefer writing all control structures without semicolon on the
+   same line. E.g. "then" should be on the next line for if statements.
+   The same applies to while, for, ...
+
  - We prefer "test" over "[ ... ]".
 
  - We do not write the noiseword "function" in front of shell
    functions.
 
+ - We prefer a space between the function name and the parentheses. The
+   opening "{" should also be on the same line.
+   E.g.: my_function () {
+
  - As to use of grep, stick to a subset of BRE (namely, no \{m,n\},
    [::], [==], nor [..]) for portability.
 
Signature · 1 line
1.7.12.rc2.11.g5d52328
#3 lore raw

Re: [PATCH v2] add some bash style we prefer

Quoted 6 lines · Heiko Voigt

During discussion of other patches these preferences have been revealed. Lets add them to the guidelines.

---
Here an updated version of the patch.

Thanks.

Quoted 43 lines · Junio C Hamano
Quoted 10 lines

Review For shell scripts specifically (not exhaustive): · line 106

Quoted 6 lines · Heiko Voigt
(quoted diff) +1 -0
@@ -97,6 +102,7 @@ For shell scripts specifically (not exhaustive):
    interface translatable. See "Marking strings for translation" in
    po/README.
 
+
 For C programs:

Probably not needed, as there is no such double space between C and Documentation sections.

Sorry about that whitespace noise.

Cheers Heiko

 Documentation/CodingGuidelines | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/CodingGuidelines +8 -0
index 4557711..e70d110 100644
@@ -76,11 +76,19 @@ For shell scripts specifically (not exhaustive):
 
  - We do not use Process Substitution <(list) or >(list).
 
+ - We prefer writing all control structures without semicolon on the
+   same line. E.g. "then" should be on the next line for if statements.
+   The same applies to while, for, ...
+
  - We prefer "test" over "[ ... ]".
 
  - We do not write the noiseword "function" in front of shell
    functions.
 
+ - We prefer a space between the function name and the parentheses. The
+   opening "{" should also be on the same line.
+   E.g.: my_function () {
+
  - As to use of grep, stick to a subset of BRE (namely, no \{m,n\},
    [::], [==], nor [..]) for portability.