CodingGuidelines: give an example for shell function preamble
[gitweb.git] / Documentation / CodingGuidelines
index 11704fb84cb3b9652223ad17631c999bafc268d8..0a574b204c00d2a577f73bf9687dbbc491797a44 100644 (file)
@@ -107,14 +107,33 @@ For shell scripts specifically (not exhaustive):
    "then" should be on the next line for if statements, and "do"
    should be on the next line for "while" and "for".
 
+       (incorrect)
+       if test -f hello; then
+               do this
+       fi
+
+       (correct)
+       if test -f hello
+       then
+               do this
+       fi
+
  - 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 () {
+ - We prefer a space between the function name and the parentheses,
+   and no space inside the parentheses. The opening "{" should also
+   be on the same line.
+
+       (incorrect)
+       my_function(){
+               ...
+
+       (correct)
+       my_function () {
+               ...
 
  - As to use of grep, stick to a subset of BRE (namely, no \{m,n\},
    [::], [==], or [..]) for portability.