# [PATCH] Document bash style we prefer for if and functions

4 messages from 2012-08-14 to 2012-08-15. Participants: Heiko Voigt, Junio C Hamano.
Thread: https://gitlist.dev/t/31253

## Heiko Voigt, 2012-08-14 20:39

Subject: [PATCH] Document bash style we prefer for if and functions
Message-ID: <20120814203931.GB33843@book.hvoigt.net>
URL: https://gitlist.dev/e/20120814203931.GB33843%40book.hvoigt.net

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

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
 Documentation/CodingGuidelines | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 4557711..0a07990 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -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
-- 
1.7.12.rc2.11.g5d52328

```

## Junio C Hamano, 2012-08-14 21:09

Subject: Re: [PATCH] Document bash style we prefer for if and functions
Message-ID: <7vipcl89kg.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vipcl89kg.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20120814203931.GB33843@book.hvoigt.net>

```
Heiko Voigt <hvoigt@hvoigt.net> writes:

> During discussion of other patches these preferences have been revealed.
> Lets add them to the guidelines.
>
> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> ---
>  Documentation/CodingGuidelines | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
> index 4557711..0a07990 100644
> --- a/Documentation/CodingGuidelines
> +++ b/Documentation/CodingGuidelines
> @@ -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

>   - 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 () {

>   - 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.

>  
>   - We use tabs to indent, and interpret tabs as taking up to

```

## Heiko Voigt, 2012-08-15 17:06

Subject: [PATCH v2] add some bash style we prefer
Message-ID: <20120815170601.GB43523@book.hvoigt.net>
URL: https://gitlist.dev/e/20120815170601.GB43523%40book.hvoigt.net
In-Reply-To: <7vipcl89kg.fsf@alter.siamese.dyndns.org>

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

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
Here an updated version of the patch.

On Tue, Aug 14, 2012 at 02:09:35PM -0700, Junio C Hamano wrote:
> Heiko Voigt <hvoigt@hvoigt.net> writes:
> > @@ -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(+)

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 4557711..e70d110 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -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.
 
-- 
1.7.12.rc2.11.g5d52328

```

## Junio C Hamano, 2012-08-15 17:55

Subject: Re: [PATCH v2] add some bash style we prefer
Message-ID: <7vzk5w59c7.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzk5w59c7.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20120815170601.GB43523@book.hvoigt.net>

```
Heiko Voigt <hvoigt@hvoigt.net> writes:

> During discussion of other patches these preferences have been revealed.
> Lets add them to the guidelines.
>
> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> ---
> Here an updated version of the patch.

Thanks.


>
> On Tue, Aug 14, 2012 at 02:09:35PM -0700, Junio C Hamano wrote:
>> Heiko Voigt <hvoigt@hvoigt.net> writes:
>> > @@ -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(+)
>
> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
> index 4557711..e70d110 100644
> --- a/Documentation/CodingGuidelines
> +++ b/Documentation/CodingGuidelines
> @@ -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.

```
